'use client' import React, { useState } from 'react' import styles from './inventory-grid.module.css' export interface InventoryItem { id: string icon?: string name?: string count?: number rarity?: 'common' | 'uncommon' | 'rare' | 'epic' | 'legendary' category?: string } export interface InventoryGridProps { items?: InventoryItem[] gridSize?: { rows: number; cols: number } onSelect?: (item: InventoryItem) => void className?: string maxSlots?: number } export function InventoryGrid({ items = [], gridSize = { rows: 4, cols: 6 }, onSelect, className = '', maxSlots, }: InventoryGridProps) { const totalSlots = maxSlots || gridSize.rows * gridSize.cols const [draggedItem, setDraggedItem] = useState(null) const [hoveredSlot, setHoveredSlot] = useState(null) const emptySlots = totalSlots - items.length const gridItems = [...items, ...Array(emptySlots).fill(null)] const rarityColor: Record, string> = { common: '#9d9d9d', uncommon: '#5fa849', rare: '#4c8cd9', epic: '#9b59b6', legendary: '#f0a500', } const handleDragStart = (itemId: string) => { setDraggedItem(itemId) } const handleDragEnd = () => { setDraggedItem(null) setHoveredSlot(null) } return (
🎒

Inventory

💰 2,450
{gridItems.map((item, index) => (
item && setHoveredSlot(index)} onDragLeave={() => setHoveredSlot(null)} onClick={() => item && onSelect?.(item)} > {item ? ( <>
handleDragStart(item.id)} onDragEnd={handleDragEnd} style={{ '--rarity': rarityColor[item.rarity || 'common'], } as React.CSSProperties} > {item.icon && {item.icon}} {item.count !== undefined && item.count > 1 && ( {item.count} )} {item.rarity && item.rarity !== 'common' && (
)}
{item.name && {item.name}} ) : (
)}
))}
{items.length}/{totalSlots}
) } export default InventoryGrid