'use client';
import { canAffordSpellCost } from '@/lib/game/stores';
import { useCombatStore, useManaStore } from '@/lib/game/stores';
import { ELEMENTS, SPELLS_DEF } from '@/lib/game/constants';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
// Format spell cost for display
function formatSpellCost(cost: { type: 'raw' | 'element'; element?: string; amount: number }): string {
if (cost.type === 'raw') {
return `${cost.amount} raw`;
}
const elemDef = ELEMENTS[cost.element || ''];
return `${cost.amount} ${elemDef?.sym || '?'}`;
}
// Get cost color
function getSpellCostColor(cost: { type: 'raw' | 'element'; element?: string; amount: number }): string {
if (cost.type === 'raw') {
return '#60A5FA';
}
return ELEMENTS[cost.element || '']?.color || '#9CA3AF';
}
export function SpellsTab() {
const spells = useCombatStore((s) => s.spells);
const activeSpell = useCombatStore((s) => s.activeSpell);
const setSpell = useCombatStore((s) => s.setSpell);
const rawMana = useManaStore((s) => s.rawMana);
const elements = useManaStore((s) => s.elements);
const spellTiers = [0, 1, 2, 3, 4];
return (
{spellTiers.map(tier => {
const spellsInTier = Object.entries(SPELLS_DEF).filter(([, def]) => def.tier === tier);
if (spellsInTier.length === 0) return null;
const tierNames = ['Basic Spells (Raw Mana)', 'Tier 1 - Elemental', 'Tier 2 - Advanced', 'Tier 3 - Master', 'Tier 4 - Legendary'];
const tierColors = ['text-gray-400', 'text-green-400', 'text-blue-400', 'text-purple-400', 'text-amber-400'];
return (
{tierNames[tier]}
{spellsInTier.map(([id, def]) => {
const state = spells?.[id];
const learned = state?.learned;
const elemDef = def.elem === 'raw' ? null : ELEMENTS[def.elem];
const isActive = activeSpell === id;
const canCast = learned && canAffordSpellCost(def.cost, rawMana, elements);
return (
{def.name}
{def.tier > 0 && (
T{def.tier}
)}
{def.elem !== 'raw' && {elemDef?.sym} {elemDef?.name}}
⚔️ {def.dmg} dmg
{/* Cost display */}
Cost: {formatSpellCost(def.cost)}
{def.desc && (
{def.desc}
)}
{def.effects && Array.isArray(def.effects) && def.effects.length > 0 && (
{def.effects.map((eff, i) => (
{eff.type === 'burn' && `🔥 Burn`}
{eff.type === 'stun' && `⚡ Stun`}
{eff.type === 'pierce' && `🎯 Pierce`}
{eff.type === 'multicast' && `✨ Multicast`}
))}
)}
{learned ? (
Learned
{isActive && Active}
{!isActive && (
)}
) : (
Not yet learned
)}
);
})}
);
})}
);
}
SpellsTab.displayName = "SpellsTab";