'use client'; import { useState, useMemo } from 'react'; import { Button } from '@/components/ui/button'; import { Progress } from '@/components/ui/progress'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Separator } from '@/components/ui/separator'; import { Anvil, Hammer, Package } from 'lucide-react'; import { FABRICATOR_RECIPES, getRecipesByManaType, canCraftRecipe, } from '@/lib/game/data/fabricator-recipes'; import { LOOT_DROPS, LOOT_RARITY_COLORS } from '@/lib/game/data/loot-drops'; import { useCraftingStore, useManaStore } from '@/lib/game/stores'; import type { FabricatorRecipe } from '@/lib/game/data/fabricator-recipes'; const MANA_TYPE_LABELS: Record = { earth: '⛰️ Earth', metal: '🔩 Metal', crystal: '💎 Crystal', sand: '🏜️ Sand', }; function RecipeCard({ recipe, materials, manaAmount, onCraft, isCrafting, }: { recipe: FabricatorRecipe; materials: Record; manaAmount: number; onCraft: (recipe: FabricatorRecipe) => void; isCrafting: boolean; }) { const { canCraft, missingMaterials, missingMana } = canCraftRecipe( recipe, materials, manaAmount, ); const rarityStyle = LOOT_RARITY_COLORS[recipe.rarity]; return (
{recipe.name}
{recipe.rarity}
{MANA_TYPE_LABELS[recipe.manaType] ?? recipe.manaType}
{recipe.description}
{recipe.gearTrait}
Materials:
{Object.entries(recipe.materials).map(([matId, amount]) => { const available = materials[matId] || 0; const matDrop = LOOT_DROPS[matId]; const hasEnough = available >= amount; return (
{matDrop?.name ?? matId} {available} / {amount}
); })}
{MANA_TYPE_LABELS[recipe.manaType]?.split(' ')[1] ?? recipe.manaType} Mana: = recipe.manaCost ? 'text-green-400' : 'text-red-400'}> {manaAmount} / {recipe.manaCost}
Craft Time: {recipe.craftTime}h
); } export function FabricatorSubTab() { const [selectedManaType, setSelectedManaType] = useState('earth'); const lootInventory = useCraftingStore((s) => s.lootInventory); const equipmentCraftingProgress = useCraftingStore((s) => s.equipmentCraftingProgress); const rawMana = useManaStore((s) => s.rawMana); const startCraftingEquipment = useCraftingStore((s) => s.startCraftingEquipment); const cancelEquipmentCrafting = useCraftingStore((s) => s.cancelEquipmentCrafting); const availableManaTypes = useMemo(() => { return [...new Set(FABRICATOR_RECIPES.map((r) => r.manaType))]; }, []); const filteredRecipes = useMemo( () => getRecipesByManaType(selectedManaType), [selectedManaType], ); const isCrafting = equipmentCraftingProgress !== null; const handleCraft = (recipe: FabricatorRecipe) => { // Use the existing equipment crafting system with a fabricator-specific blueprint ID startCraftingEquipment(`fabricator-${recipe.id}`); }; return (
{/* Mana type filter */}
{availableManaTypes.map((mt) => ( ))}
{/* Recipe list */} {MANA_TYPE_LABELS[selectedManaType] ?? selectedManaType} Recipes {isCrafting ? (
Crafting: {equipmentCraftingProgress.blueprintId}
{equipmentCraftingProgress.progress.toFixed(1)}h /{' '} {equipmentCraftingProgress.required.toFixed(1)}h Mana spent: {equipmentCraftingProgress.manaSpent}
) : (
{filteredRecipes.length === 0 ? (

No recipes for this mana type yet.

) : ( filteredRecipes.map((recipe) => ( )) )}
)}
{/* Materials inventory */} Materials ({Object.values(lootInventory.materials).reduce((a, b) => a + b, 0)}) {Object.keys(lootInventory.materials).length === 0 ? (

No materials collected yet.

Defeat floors to gather materials!

) : (
{Object.entries(lootInventory.materials).map(([matId, count]) => { if (count <= 0) return null; const drop = LOOT_DROPS[matId]; if (!drop) return null; const rarityStyle = LOOT_RARITY_COLORS[drop.rarity]; return (
{drop.name}
x{count}
); })}
)}
); } FabricatorSubTab.displayName = 'FabricatorSubTab';