import { Separator } from "@/components/ui/separator"
import { formatNumber } from "@/lib/formatters"
import { getBuildBattleRank } from "@/lib/hypixel/build-battle/general"
import { NonNullStats } from "@/lib/schema/player"
import { cn } from "@/lib/utils"
import GeneralStats from "../GeneralStats"
import BuildBattleTitleProgress from "./progress"
import BuildBattleGeneralStats from "./stats"
import BuildBattleStatsTable from "./table"

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

    const rank = getBuildBattleRank(stats.score)

    return (
        <GeneralStats
            id="build-battle"
            title="Build Battle"
            collapsedStats={[
                {
                    title: <p>Title</p>,
                    stat: <p className={cn(rank.bold && "font-bold", `text-mc-${rank.color}`)}>{rank.name}</p>
                },
                {
                    title: <p>Wins</p>,
                    stat: <p className="text-muted-foreground">{formatNumber(stats.wins)}</p>
                }
            ]}
        >
            <Separator className="my-4" />
            <BuildBattleTitleProgress score={stats.score} />
            <Separator className="my-4" />
            <BuildBattleGeneralStats stats={stats} />
            <Separator className="my-4" />
            <BuildBattleStatsTable stats={stats} />
            <Separator className="my-4" />
        </GeneralStats>
    )
}
