'use client'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { ELEMENTS, SPELLS_DEF } from '@/lib/game/constants'; import { ENCHANTMENT_EFFECTS } from '@/lib/game/data/enchantment-effects'; import { calcDamage, canAffordSpellCost, fmt } from '@/lib/game/store'; import { formatSpellCost, getSpellCostColor } from '@/lib/game/formatting'; interface SpellsTabProps { store: { spells: Record; equippedInstances: Record; equipmentInstances: Record; activeSpell: string; rawMana: number; elements: Record; signedPacts: number[]; unlockedEffects: string[]; setSpell: (spellId: string) => void; }; } export function SpellsTab({ store }: SpellsTabProps) { // Get spells from equipment const equipmentSpellIds: string[] = []; const spellSources: Record = {}; for (const instanceId of Object.values(store.equippedInstances)) { if (!instanceId) continue; const instance = store.equipmentInstances[instanceId]; if (!instance) continue; for (const ench of instance.enchantments) { const effectDef = ENCHANTMENT_EFFECTS[ench.effectId]; if (effectDef?.effect.type === 'spell' && effectDef.effect.spellId) { const spellId = effectDef.effect.spellId; if (!equipmentSpellIds.includes(spellId)) { equipmentSpellIds.push(spellId); } if (!spellSources[spellId]) { spellSources[spellId] = []; } spellSources[spellId].push(instance.name); } } } const canCastSpell = (spellId: string): boolean => { const spell = SPELLS_DEF[spellId]; if (!spell) return false; return canAffordSpellCost(spell.cost, store.rawMana, store.elements); }; return (
{/* Equipment-Granted Spells */}

✨ Known Spells

Spells are obtained by enchanting equipment with spell effects. Visit the Crafting tab to design and apply enchantments.

{equipmentSpellIds.length > 0 ? (
{equipmentSpellIds.map(id => { const def = SPELLS_DEF[id]; if (!def) return null; const isActive = store.activeSpell === id; const canCast = canCastSpell(id); const elemDef = def.elem === 'raw' ? null : ELEMENTS[def.elem]; const sources = spellSources[id] || []; return (
{def.name} Equipment
{def.elem !== 'raw' && {elemDef?.sym} {elemDef?.name}} ⚔️ {def.dmg} dmg
Cost: {formatSpellCost(def.cost)}
From: {sources.join(', ')}
{isActive ? ( Active ) : ( )}
); })}
) : (
No spells known yet
Enchant a staff with a spell effect to gain spells
)}
{/* Pact Spells (from guardian defeats) */} {store.signedPacts.length > 0 && (

🏆 Pact Spells

Spells earned through guardian pacts appear here.

)} {/* Spell Reference - show all available spells for enchanting */}

📚 Spell Reference

These spells can be applied to equipment through the enchanting system. Research enchantment effects in the Skills tab to unlock them for designing.

{Object.entries(SPELLS_DEF).map(([id, def]) => { const elemDef = def.elem === 'raw' ? null : ELEMENTS[def.elem]; const isUnlocked = store.unlockedEffects?.includes(`spell_${id}`); return (
{def.name}
{def.tier > 0 && T{def.tier}} {isUnlocked && Unlocked}
{def.elem !== 'raw' && {elemDef?.sym} {elemDef?.name}} ⚔️ {def.dmg} dmg
Cost: {formatSpellCost(def.cost)}
{def.desc && (
{def.desc}
)} {!isUnlocked && (
Research to unlock for enchanting
)}
); })}
); }