import { useState, type ReactNode } from "react"; import { cn } from "@/lib/utils"; import type { BadgeDef, BadgeStato, Grado } from "@/lib/badges"; import { gradoMeta, gradiOrdine, descrizioneSoglie } from "@/lib/badges"; import { Barra } from "@/components/motion/Barra"; import { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger, } from "@/components/ui/drawer"; function DettaglioBadge({ def, stato }: { def: BadgeDef; stato?: BadgeStato }) { const Icon = def.icon; const grado = stato?.grado ?? null; const meta = grado ? gradoMeta[grado] : null; const prossimo = stato?.prossimo ?? null; return (
{def.nome} {def.descrizione}
{stato ? (

Stato attuale

{grado ? ( {meta?.label} ) : ( In progresso )}

{stato.valore} {def.unita}

{stato.prossimaSoglia ? ( <>

Mancano {stato.prossimaSoglia - stato.valore} {def.unita} per il{" "} {gradoMeta[stato.prossimo as Grado].label.toLowerCase()}

) : (

Hai raggiunto il livello massimo.

)}
) : null}

Soglie

{gradiOrdine.map((g) => { const gm = gradoMeta[g]; const raggiunto = grado ? gradiOrdine.indexOf(grado) >= gradiOrdine.indexOf(g) : false; return (

{gm.label}

{def.soglie[g]}

{def.unita}

); })}
{def.celebrazione ? (

“{def.celebrazione}”

) : null}
); } /** Drawer cliccabile che mostra la descrizione e le soglie di un badge. */ export function BadgeDrawer({ def, stato, children, }: { def: BadgeDef; stato?: BadgeStato; children: ReactNode; }) { const [open, setOpen] = useState(false); return ( {children} {def.nome} {def.descrizione} ); }