import { formatNumber } from "@/lib/formatters"
import { getLatestRoom, getWalletMax } from "@/lib/hypixel/bedwars"
import { Player } from "@/lib/schema/player"
import { BasicStat, Stat } from "../../_components/Stats"
import { BedWarsPrestige } from "./bedwars-components"

export default function BedwarsGeneralStats(
    { statsChecked, level, percent, kd, fkd, bbl, wl }: {
        statsChecked: Player["player"]["stats"]["Bedwars"]
        level: number
        percent: number
        kd: string
        fkd: string
        bbl: string
        wl: string
    }
) {
    const stats = statsChecked!

    return (
        <div className="flex mb-10">
            <div className="flex-1">
                <BasicStat title="Level: " value={`${level}.${percent.toFixed(0)}`} />
                <Stat title="Prestige: ">
                    <BedWarsPrestige level={level} />
                </Stat>
                <BasicStat title="Tokens: " value={formatNumber(stats.coins)} className="text-mc-dark-green" />
                <p>
                    <br />
                </p>
                <BasicStat title="Kills: " value={formatNumber(stats.kills_bedwars)} />
                <BasicStat title="Deaths: " value={formatNumber(stats.deaths_bedwars)} />
                <BasicStat title="Kill/Death Ratio: " value={kd} />
                <BasicStat title="Final Kills: " value={formatNumber(stats.final_kills_bedwars)} />
                <BasicStat title="Final Deaths: " value={formatNumber(stats.final_deaths_bedwars)} />
                <BasicStat title="Final Kill/Death Ratio: " value={fkd} />
            </div>
            <div className="flex-1">
                <BasicStat title="Winstreak: " value={stats.winstreak ?? "?"} />
                <BasicStat title="Wins: " value={formatNumber(stats.wins_bedwars)} />
                <BasicStat title="Losses: " value={formatNumber(stats.losses_bedwars)} />
                <BasicStat title="Win/Loss Ratio: " value={wl} />
                <p>
                    <br />
                </p>
                <BasicStat title="Beds Broken: " value={stats.beds_broken_bedwars} />
                <BasicStat title="Beds Lost: " value={stats.beds_lost_bedwars} />
                <BasicStat title="Beds Broken/Lost: " value={bbl} />
                <p>
                    <br />
                </p>
                <BasicStat title="Total Challenges Completed: " value={stats.total_challenges_completed} />
            </div>
            <div className="flex-1">
                <Stat title={"Slumber Tickets: "}>
                    <span className="text-mc-aqua">
                        {stats.slumber?.tickets === undefined ? "None" : formatNumber(stats.slumber.tickets)}
                    </span>
                    <span className="text-muted-foreground">
                        {`/${formatNumber(getWalletMax(stats.slumber?.bag_type))}`}
                    </span>
                </Stat>
                <BasicStat
                    title="Lifetime Slumber Tickets: "
                    value={formatNumber(stats.slumber?.total_tickets_earned ?? 0)}
                    className="text-mc-aqua"
                />
                <BasicStat title="Doors Unlocked: " value={getLatestRoom(stats.slumber?.room) ?? "None"} />
                <BasicStat title="XP Doublers: " value={formatNumber(stats.slumber?.doublers ?? 0)} className="text-mc-dark-aqua" />
                <p>
                    <br />
                </p>
                <BasicStat title="Iron Collected: " value={formatNumber(stats.iron_resources_collected_bedwars)} />
                <BasicStat title="Gold Collected: " value={formatNumber(stats.gold_resources_collected_bedwars)} />
                <BasicStat title="Diamonds Collected: " value={formatNumber(stats.diamond_resources_collected_bedwars)} />
                <BasicStat title="Emeralds Collected: " value={formatNumber(stats.emerald_resources_collected_bedwars)} />
                <BasicStat title="Total Shop Purchases: " value={formatNumber(stats._items_purchased_bedwars)} />
            </div>
        </div>
    )
}
