import { Separator } from "@/components/ui/separator"
import { formatNumber } from "@/lib/formatters"
import { getWoolGamesLevel, getWoolGamesPrestige, getWoolGamesPretigeIcon } from "@/lib/hypixel/woolgames/general"
import { NonNullStats } from "@/lib/schema/player"
import Multicolored from "../../_components/Multicolored"
import GeneralStats from "../GeneralStats"
import { WoolGamesCaptureTheWool, WoolGamesSheepWars, WoolGamesWoolWars } from "./modes"
import WoolGamesProgress from "./progress"
import WoolGamesGeneralStats from "./stats"

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

    const level = getWoolGamesLevel(stats.progression?.experience)
    const icon = getWoolGamesPretigeIcon(stats.wool_wars_prestige_icon)
    const pres = getWoolGamesPrestige(level)
    const kills = (stats.capture_the_wool?.stats?.kills || 0) + (stats.sheep_wars?.stats?.kills || 0) + (stats.wool_wars?.stats?.kills || 0)
    const wins = (stats.capture_the_wool?.stats?.participated_wins || 0) + (stats.sheep_wars?.stats?.wins || 0) + (stats.wool_wars?.stats?.wins || 0)

    return (
        <GeneralStats
            id="woolgames"
            title="Wool Games"
            collapsedStats={[
                {
                    title: <p>Level</p>,
                    stat: <Multicolored val={`[${Math.floor(level)}${icon}]`} color={pres.colormap} />
                },
                {
                    title: <p>Kills</p>,
                    stat: <p className="text-muted-foreground">{formatNumber(kills)}</p>
                },
                {
                    title: <p>Wins</p>,
                    stat: <p className="text-muted-foreground">{formatNumber(wins)}</p>
                }
            ]}
        >
            <Separator className="my-4" />
            <WoolGamesProgress xp={stats.progression?.experience || 0} level={level} />
            <Separator className="my-4" />
            <WoolGamesGeneralStats stats={stats} level={level} kills={kills} wins={wins} />
            <Separator className="my-4" />
            <WoolGamesCaptureTheWool ctw={stats.capture_the_wool} />
            <Separator className="my-4" />
            <WoolGamesSheepWars sw={stats.sheep_wars} />
            <Separator className="my-4" />
            <WoolGamesWoolWars ww={stats.wool_wars} />
            <Separator className="my-4" />
        </GeneralStats>
    )
}
