import { Separator } from "@/components/ui/separator"
import { formatNumber } from "@/lib/formatters"
import { getCopsAndCrimsScoreColor } from "@/lib/hypixel/copsandcrims/general"
import { devide } from "@/lib/hypixel/general"
import { NonNullStats } from "@/lib/schema/player"
import { GeneralStats } from "../stats-components"
import CopsAndCrimsGeneralStats from "./stats"
import CopsAndCrimsStatTable from "./table"
import CopsAndCrimsWeaponStats from "./weapons"

export default function CopsAndCrimsStats({ stats }: { stats: NonNullStats["CopsAndCrims"] }) {
    if (!stats) return null

    const kills = stats.kills + stats.kills_deathmatch + stats.kills_gungame
    const assists = stats.assists + stats.assists_deathmatch + stats.assists_gungame
    const deaths = stats.deaths + stats.deaths_deathmatch + stats.deaths_gungame
    const wins = stats.game_wins + stats.game_wins_deathmatch + stats.game_wins_gungame
    const kd = formatNumber(devide(kills, deaths))
    const score = Math.floor(kills / 2 + (stats.bombs_planted + stats.bombs_defused) / 3 + wins + devide(kills, stats.shots_fired) * 200)
    const scoreColor = getCopsAndCrimsScoreColor(score)

    return (
        <GeneralStats
            id="cops-and-crims"
            title="Cops And Crims"
            collapsedStats={[
                {
                    title: <p>Score</p>,
                    stat: <p className={`text-mc-${scoreColor}`}>{formatNumber(score)}</p>
                },
                {
                    title: <p>Kills</p>,
                    stat: <p className="text-muted-foreground">{formatNumber(kills)}</p>
                },
                {
                    title: <p>KD</p>,
                    stat: <p className="text-muted-foreground">{kd}</p>
                },
                {
                    title: <p>Wins</p>,
                    stat: <p className="text-muted-foreground">{formatNumber(wins)}</p>
                }
            ]}
        >
            <Separator className="my-4" />
            <CopsAndCrimsGeneralStats stats={stats} wins={wins} kills={kills} assits={assists} deaths={deaths} />
            <Separator className="my-4" />
            <CopsAndCrimsStatTable stats={stats} />
            <Separator className="my-4" />
            <CopsAndCrimsWeaponStats stats={stats} />
            <Separator className="my-4" />
        </GeneralStats>
    )
}
