'use client';
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 { Package, Sparkles, Trash2, Anvil } from 'lucide-react';
import { CRAFTING_RECIPES, canCraftRecipe } from '@/lib/game/data/crafting-recipes';
import { LOOT_DROPS, RARITY_COLORS } from '@/lib/game/data/loot-drops';
import type { EquipmentInstance, AppliedEnchantment, LootInventory, EquipmentCraftingProgress } from '@/lib/game/types';
import { fmt } from '@/lib/game/stores';
import { useCraftingStore, useCombatStore, useManaStore } from '@/lib/game/stores';
export function EquipmentCrafter() {
const lootInventory = useCraftingStore((s) => s.lootInventory);
const equipmentCraftingProgress = useCraftingStore((s) => s.equipmentCraftingProgress);
const rawMana = useManaStore((s) => s.rawMana);
const currentAction = useCombatStore((s) => s.currentAction);
const startCraftingEquipment = useCraftingStore((s) => s.startCraftingEquipment);
const cancelEquipmentCrafting = useCraftingStore((s) => s.cancelEquipmentCrafting);
const deleteMaterial = useCraftingStore((s) => s.deleteMaterial);
return (
{/* Blueprint Selection */}
Available Blueprints
{equipmentCraftingProgress ? (
Crafting: {CRAFTING_RECIPES[equipmentCraftingProgress.blueprintId]?.name}
{equipmentCraftingProgress.progress.toFixed(1)}h / {equipmentCraftingProgress.required.toFixed(1)}h
Mana spent: {fmt(equipmentCraftingProgress.manaSpent)}
) : (
{lootInventory.blueprints.length === 0 ? (
No blueprints discovered yet.
Defeat guardians to find blueprints!
) : (
lootInventory.blueprints.map(bpId => {
const recipe = CRAFTING_RECIPES[bpId];
if (!recipe) return null;
const { canCraft, missingMaterials, missingMana } = canCraftRecipe(
recipe,
lootInventory.materials,
rawMana
);
const rarityStyle = RARITY_COLORS[recipe.rarity];
return (
{recipe.name}
{recipe.rarity}
{recipe.equipmentTypeId ? 'Equipment' : 'Other'}
{recipe.description}
Materials:
{Object.entries(recipe.materials).map(([matId, amount]) => {
const available = lootInventory.materials[matId] || 0;
const matDrop = LOOT_DROPS[matId];
const hasEnough = available >= amount;
return (
{matDrop?.name || matId}
{available} / {amount}
);
})}
Mana Cost:
= recipe.manaCost ? 'text-green-400' : 'text-red-400'}>
{fmt(recipe.manaCost)}
Craft Time:
{recipe.craftTime}h
);
})
)}
)}
{/* 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 = RARITY_COLORS[drop.rarity];
return (
);
})}
)}
);
}
EquipmentCrafter.displayName = "EquipmentCrafter";