// ─── Shared Formatting Utilities ───────────────────────────────────────────────── // Utility functions for consistent formatting across components import { ELEMENTS } from '@/lib/game/constants'; import type { SpellCost } from '@/lib/game/types'; // Re-export number formatting functions from computed-stats.ts export { fmt, fmtDec } from './computed-stats'; /** * Format a spell cost for display */ export function formatSpellCost(cost: SpellCost): string { if (cost.type === 'raw') { return `${cost.amount} raw`; } const elemDef = ELEMENTS[cost.element || '']; return `${cost.amount} ${elemDef?.sym || '?'}`; } /** * Get the display color for a spell cost */ export function getSpellCostColor(cost: SpellCost): string { if (cost.type === 'raw') { return '#60A5FA'; // Blue for raw mana } return ELEMENTS[cost.element || '']?.color || '#9CA3AF'; } /** * Format study time in hours to human-readable string */ export function formatStudyTime(hours: number): string { if (hours < 1) return `${Math.round(hours * 60)}m`; return `${hours.toFixed(1)}h`; } /** * Format time (hour of day) to HH:MM format */ export function formatHour(hour: number): string { const h = Math.floor(hour); const m = Math.floor((hour % 1) * 60); return `${h.toString().padStart(2, '0')}:${m.toString().padStart(2, '0')}`; }