import { formatNumber, formatSecondsToTime } from "@/lib/formatters"
import { devide, romanize } from "@/lib/hypixel/general"
import { getPitLevelColor, getPitPrestige, getPitPrestigeColor } from "@/lib/hypixel/pit/general"
import { getPitLevel } from "@/lib/hypixel/pit/level"
import { NonNullStats } from "@/lib/schema/player"
import { BasicStat } from "../../_components/Stats"

export default function PitGeneralStats({ stats }: { stats: NonNullable<NonNullStats["Pit"]> }) {
    const prestige = getPitPrestige(stats)
    const level = getPitLevel(stats.profile.xp, prestige)
    const pretigeColor = getPitPrestigeColor(prestige)
    const levelColor = getPitLevelColor(level)
    const kah = formatNumber(devide(stats.kills + stats.assists, stats.playtime_minutes / 60))
    const gh = formatNumber(devide(stats.cash_earned, stats.playtime_minutes / 60))
    const xph = formatNumber(devide(stats.profile.xp, stats.playtime_minutes / 60))
    const kd = formatNumber(devide(stats.kills, stats.deaths))
    const kad = formatNumber(devide((stats.kills, stats.assists), stats.deaths))
    const ddr = formatNumber(devide(stats.damage_dealt, stats.damage_received))
    const sa = formatNumber(devide(stats.sword_hits, stats.left_clicks) * 100)
    const aa = formatNumber(devide(stats.arrow_hits, stats.arrows_fired) * 100)

    return (
        <div className="flex">
            <div className="flex-1">
                <BasicStat title="Pretige: " value={prestige === 0 ? "None" : romanize(prestige)} className={`font-bold text-mc-${pretigeColor}`} />
                <BasicStat title="Level: " value={level} className={`font-bold text-mc-${levelColor}`} />
                <BasicStat title="Gold: " value={formatNumber(Math.floor(stats.profile.cash))} className="text-mc-gold" />
                <BasicStat title="Lifetime Gold: " value={formatNumber(Math.floor(stats.cash_earned))} className="text-mc-gold" />
                <BasicStat title="XP: " value={formatNumber(stats.profile.xp)} className="text-mc-aqua" />
                <BasicStat title="Renown: " value={formatNumber(stats.profile.renown)} className="text-mc-yellow" />
                <p>
                    <br />
                </p>
                <BasicStat title="Playtime: " value={formatSecondsToTime(stats.playtime_minutes * 60)} />
                <BasicStat title="Kill+Assists/Hour: " value={kah} />
                <BasicStat title="Gold/Hour: " value={gh} className="text-mc-gold" />
                <BasicStat title="XP/Hour: " value={xph} className="text-mc-aqua" />
                <p>
                    <br />
                </p>
                <BasicStat title="Kills: " value={formatNumber(stats.kills)} />
                <BasicStat title="Assists: " value={formatNumber(stats.assists)} />
                <BasicStat title="Deaths: " value={formatNumber(stats.deaths)} />
                <BasicStat title="Kill/Death Ratio: " value={kd} />
                <BasicStat title="Kill+Assist/Death Ratio: " value={kad} />
                <BasicStat title="Highest Killstreak: " value={formatNumber(stats.max_streak)} />
            </div>
            <div className="flex-1">
                <BasicStat title="Damage Dealt: " value={formatNumber(stats.damage_dealt)} />
                <BasicStat title="Damage Received: " value={formatNumber(stats.damage_received)} />
                <BasicStat title="Melee Damage Dealt: " value={formatNumber(stats.melee_damage_dealt)} />
                <BasicStat title="Melee Damage Received: " value={formatNumber(stats.melee_damage_received)} />
                <BasicStat title="Bow Damage Dealt: " value={formatNumber(stats.bow_damage_dealt)} />
                <BasicStat title="Bow Damage Received: " value={formatNumber(stats.bow_damage_received)} />
                <BasicStat title="Damage Dealt/Received Ratio: " value={ddr} />
                <p>
                    <br />
                </p>
                <BasicStat title="Sword Hits: " value={formatNumber(stats.sword_hits)} />
                <BasicStat title="Sword Swings: " value={formatNumber(stats.left_clicks)} />
                <BasicStat title="Sword Hit Accuracy: " value={`${sa}%`} />
                <p>
                    <br />
                </p>
                <BasicStat title="Arrow Hits: " value={formatNumber(stats.arrow_hits)} />
                <BasicStat title="Arrow Shot: " value={formatNumber(stats.arrows_fired)} />
                <BasicStat title="Arrow Hit Accuracy: " value={`${aa}%`} />
                <p>
                    <br />
                </p>
                <BasicStat title="Contracts Completed: " value={formatNumber(stats.contracts_completed)} />
                <BasicStat title="Jumps into the Pit: " value={formatNumber(stats.jumped_into_pit)} />
                <BasicStat title="Launcher Launches: " value={formatNumber(stats.launched_by_launchers)} />
            </div>
            <div className="flex-1">
                <BasicStat title="Golden Apples Eaten: " value={formatNumber(stats.gapple_eaten)} />
                <BasicStat title="Golden Head Eaten: " value={formatNumber(stats.ghead_eaten)} />
                <BasicStat title="Soups Drunk: " value={formatNumber(stats.soups_drank)} />
                <BasicStat title="Rage Potatoes: " value={formatNumber(stats.rage_potatoes_eaten)} />
                <BasicStat title="Fishing Rods Thrown: " value={formatNumber(stats.fishing_rod_launched)} />
                <BasicStat title="Lava Buckets Used: " value={formatNumber(stats.lava_bucket_emptied)} />
                <BasicStat title="Diamond Items Purchased: " value={formatNumber(stats.diamond_items_purchased)} />
                <BasicStat title="Blocks Placed: " value={formatNumber(stats.blocks_placed)} />
                <BasicStat title="Blocks Broken: " value={formatNumber(stats.blocks_broken)} />
                <p>
                    <br />
                </p>
                <BasicStat title="Tier 1 Mystics Enchanted: " value={formatNumber(stats.enchanted_tier1)} />
                <BasicStat title="Tier 2 Mystics Enchanted: " value={formatNumber(stats.enchanted_tier2)} />
                <BasicStat title="Tier 3 Mystics Enchanted: " value={formatNumber(stats.enchanted_tier3)} />
                <BasicStat title="Dark Pants Created: " value={formatNumber(stats.dark_pants_crated)} />
                <p>
                    <br />
                </p>
                <BasicStat title="Wheat Farmed: " value={formatNumber(stats.wheat_farmed)} />
                <BasicStat title="Fished Items: " value={formatNumber(stats.fished_anything)} />
                <BasicStat title="Fished Fish: " value={formatNumber(stats.fishes_fished)} />
                <BasicStat title="King's Quest Completions: " value={formatNumber(stats.king_quest_completion)} />
                <BasicStat title="Sewer Treasures Found: " value={formatNumber(stats.sewer_treasures_found)} />
            </div>
        </div>
    )
}
