import { AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
import { Card, CardContent } from "@/components/ui/card"
import { Separator } from "@/components/ui/separator"
import { formatNumber } from "@/lib/formatters"
import { devide } from "@/lib/hypixel/general"
import { getStatsCombined } from "@/lib/hypixel/uhc/general"
import { getUhcStarValue } from "@/lib/hypixel/uhc/level"
import { NonNullStats } from "@/lib/schema/player"
import CollapsedStats from "../../_components/CollapsedStats"
import UHCProgress from "./progress"
import UHCGeneralStats from "./stats"

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

    const combined = getStatsCombined(stats)
    const kd = formatNumber(devide(combined.kills, combined.deaths))
    const star = getUhcStarValue(stats.score)

    return (
        <AccordionItem value="uhc">
            <Card className="py-0">
                <CardContent>
                    <AccordionTrigger className="items-center py-2 hover:no-underline hover:cursor-pointer">
                        <h1 className="text-xl font-bold">UHC</h1>
                        <div className="flex gap-4">
                            <CollapsedStats
                                stats={[
                                    {
                                        title: <p>Star</p>,
                                        stat: <p className="text-mc-gold">{`[${star}✫]`}</p>
                                    },
                                    {
                                        title: <p>KD</p>,
                                        stat: <p className="text-muted-foreground">{kd}</p>
                                    },
                                    {
                                        title: <p>Wins</p>,
                                        stat: <p className="text-muted-foreground">{formatNumber(combined.wins)}</p>
                                    }
                                ]}
                            />
                        </div>
                    </AccordionTrigger>
                    <AccordionContent>
                        <Separator className="my-4" />
                        <UHCProgress score={stats.score} />
                        <Separator className="my-4" />
                        <UHCGeneralStats stats={stats} kills={combined.kills} deaths={combined.deaths} heads={combined.heads} wins={combined.wins} />
                    </AccordionContent>
                </CardContent>
            </Card>
        </AccordionItem>
    )
}
