'use client'; import { useState } from 'react'; import { Package, Trash2 } from 'lucide-react'; import type { EquipmentInstance, EquipmentSlot } from '@/lib/game/types'; import { EQUIPMENT_TYPES, getValidSlotsForEquipmentType } from '@/lib/game/data/equipment'; import { RARITY_CSS_VAR, RARITY_GLOW_CSS_VAR } from '@/components/game/LootInventory/types'; import { CATEGORY_ICONS } from '@/components/game/LootInventory/icons'; import { ActionButton } from '@/components/ui/action-button'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from '@/components/ui/alert-dialog'; interface InventoryListProps { inventoryItems: [string, EquipmentInstance][]; equippedInstances: Record; onEquip: (instanceId: string, slot: EquipmentSlot) => boolean; onDelete: (instanceId: string) => void; } export function InventoryList({ inventoryItems, equippedInstances, onEquip, onDelete }: InventoryListProps) { const [selectedSlot, setSelectedSlot] = useState>({}); if (inventoryItems.length === 0) { return (
No items in inventory. Craft or find equipment to fill your slots.
); } return (
{inventoryItems.map(([instanceId, instance]) => { const type = EQUIPMENT_TYPES[instance.typeId]; const Icon = type ? CATEGORY_ICONS[type.category] || Package : Package; const rarityColor = RARITY_CSS_VAR[instance.rarity] || 'var(--rarity-common)'; const rarityGlow = RARITY_GLOW_CSS_VAR[instance.rarity] || 'var(--rarity-common-glow)'; const validSlots = type ? getValidSlotsForEquipmentType(type) : []; const chosenSlot = selectedSlot[instanceId]; const availableSlots = validSlots.filter((s) => !equippedInstances[s]); return (
{instance.name}
{type?.name || instance.typeId} • {instance.usedCapacity}/{instance.totalCapacity} cap
{instance.rarity} • {instance.enchantments.length} enchant{instance.enchantments.length !== 1 ? 's' : ''} • {instance.quality}% quality
{availableSlots.length > 1 ? ( ) : null} { const slot = availableSlots.length === 1 ? availableSlots[0] : chosenSlot; if (slot) { onEquip(instanceId, slot); setSelectedSlot((prev) => { const next = { ...prev }; delete next[instanceId]; return next; }); } }} disabled={availableSlots.length === 0 || (availableSlots.length > 1 && !chosenSlot)} > Equip Delete {instance.name}? This action cannot be undone. The item will be permanently destroyed. Cancel onDelete(instanceId)}> Delete
); })}
); }