"use client" import { Card, CardContent } from "@/components/ui/card" import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible" import { Separator } from "@/components/ui/separator" import { formatNumber } from "@/lib/formatters" import { getProgress } from "@/lib/hypixel/general" import { getSkywarsLevel, getSkywarsXpForLevel } from "@/lib/hypixel/skyWarsLevel" import { NonNullStats } from "@/lib/schema/player" import { ChevronDown, ChevronUp } from "lucide-react" import { useEffect, useRef, useState } from "react" import CollapsedStats from "../../_components/CollapsedStats" import { SkywarsLevel, SkywarsProgress } from "./components" import SkyWarsGeneralStats from "./stats" import SkywarsStatTable from "./table" export default function SkyWarsStats({ stats }: { stats: NonNullStats["SkyWars"] }) { const ref = useRef(null) const [opened, setOpened] = useState(false) useEffect(() => { if (!ref.current) return const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { if (mutation.type === "attributes" && mutation.attributeName === "data-state") { const dataState = ref.current?.getAttribute("data-state") setOpened(dataState === "open") } }) }) observer.observe(ref.current, { attributes: true, attributeFilter: ["data-state"] }) return () => observer.disconnect() }, []) if (!stats) return null const level = getSkywarsLevel(stats.skywars_experience) const kd = (stats.kills / stats.deaths).toFixed(2) const wl = (stats.wins / stats.losses).toFixed(2) const percent = getProgress( getSkywarsXpForLevel(Math.floor(level)), stats.skywars_experience, getSkywarsXpForLevel(Math.floor(level) + 1) ) return (

SkyWars

Level

, stat: }, { title:

KD

, stat:

{kd}

}, { title:

Wins

, stat:

{formatNumber(stats.wins)}

}, { title:

WL

, stat:

{wl}

} ]} />
{opened === false ? : }
) }