'use client';
import { useGameStore, canAffordSpellCost } from '@/lib/game/store';
import { ELEMENTS, SPELLS_DEF } from '@/lib/game/constants';
import { useStudyStats } from '@/lib/game/hooks/useGameDerived';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Progress } from '@/components/ui/progress';
// 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';
}
// Format study time
function formatStudyTime(hours: number): string {
if (hours < 1) return `${Math.round(hours * 60)}m`;
return `${hours.toFixed(1)}h`;
}
export function SpellsTab() {
const store = useGameStore();
const { studySpeedMult, studyCostMult } = useStudyStats();
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 = store.spells[id];
const learned = state?.learned;
const isStudying = store.currentStudyTarget?.id === id;
const elemDef = def.elem === 'raw' ? null : ELEMENTS[def.elem];
const baseStudyTime = def.studyTime || (def.tier * 4);
const isActive = store.activeSpell === id;
const canCast = learned && canAffordSpellCost(def.cost, store.rawMana, store.elements);
// Apply skill modifiers
const studyTime = baseStudyTime / studySpeedMult;
const unlockCost = Math.floor(def.unlock * studyCostMult);
// Can start studying?
const canStudy = !learned && !isStudying && store.rawMana >= unlockCost;
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 && 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 && (
)}
) : isStudying ? (
Studying... {formatStudyTime(state?.studyProgress || 0)}/{formatStudyTime(studyTime)}
) : (
1 ? 'text-green-400' : ''}>
Study: {formatStudyTime(studyTime)}{studySpeedMult > 1 && ({Math.round(studySpeedMult * 100)}% speed)}
{' • '}
Cost: {fmt(unlockCost)} mana{studyCostMult < 1 && ({Math.round(studyCostMult * 100)}% cost)}
)}
);
})}
);
})}
);
}