"use client"; import { useState } from "react"; import { X, Loader2 } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle, } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import { EQUIPMENT_SLOTS } from "@/lib/constants"; import type { Character } from "@/lib/types"; import { GameIcon } from "@/components/ui/game-icon"; import { cn } from "@/lib/utils"; import { executeAction } from "@/lib/api-client"; import { toast } from "sonner"; interface EquipmentGridProps { character: Character; onActionComplete?: () => void; } export function EquipmentGrid({ character, onActionComplete }: EquipmentGridProps) { const [pendingSlot, setPendingSlot] = useState(null); async function handleUnequip(slotKey: string) { const slot = slotKey.replace("_slot", ""); setPendingSlot(slotKey); try { await executeAction(character.name, "unequip", { slot }); toast.success(`Unequipped ${slot}`); onActionComplete?.(); } catch (err) { toast.error( `Unequip failed: ${err instanceof Error ? err.message : "Unknown error"}` ); } finally { setPendingSlot(null); } } return ( Equipment
{EQUIPMENT_SLOTS.map((slot) => { const itemCode = character[slot.key as keyof Character] as string; const isEmpty = !itemCode; const isPending = pendingSlot === slot.key; let quantity: number | null = null; if (slot.key === "utility1_slot" && itemCode) { quantity = character.utility1_slot_quantity; } else if (slot.key === "utility2_slot" && itemCode) { quantity = character.utility2_slot_quantity; } return (
{slot.label} {isEmpty ? ( Empty ) : (
{itemCode} {quantity !== null && quantity > 0 && ( x{quantity} )}
)} {/* Unequip button - shown on hover */} {!isEmpty && (

Unequip {slot.label}

)}
); })}
); }