/* eslint-disable @next/next/no-img-element -- Scryfall mana SVG URLs; next/image migration is out of scope. */ import { useState, useEffect } from 'react'; import { parseManaSymbols, getColorSymbol } from '../lib/mana-symbols'; /** * Individual mana symbol component */ function ManaSymbol({ symbol, color, name, scryfall_uri, size = 'md', useSVG = false }) { const sizeClasses = { xs: 'w-3 h-3 text-xs', sm: 'w-4 h-4 text-xs', md: 'w-5 h-5 text-sm', lg: 'w-6 h-6 text-base', xl: 'w-8 h-8 text-lg' }; const isGradient = color.includes('linear-gradient'); // If using SVG and we have a Scryfall URI, render the SVG if (useSVG && scryfall_uri) { return ( {name} ); } // Default circular symbol rendering return ( {symbol} ); } /** * Mana cost display component * Renders a mana cost string as individual mana symbols */ export function ManaCost({ cost, size = 'md', className = '', useSVG = false }) { const [symbols, setSymbols] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { async function loadSymbols() { if (!cost) { setSymbols([]); setLoading(false); return; } try { const parsedSymbols = await parseManaSymbols(cost); setSymbols(parsedSymbols); } catch (error) { console.error('Error parsing mana symbols:', error); setSymbols([]); } finally { setLoading(false); } } loadSymbols(); }, [cost]); if (!cost) return null; if (loading) { return (
); } if (symbols.length === 0) return null; return (
{symbols.map((symbolData, index) => ( ))}
); } /** * Color identity display component * Shows the color identity of a card using mana symbols */ export function ColorIdentity({ colors, size = 'sm', className = '', useSVG = false }) { if (!colors || colors.length === 0) { // Show colorless symbol for cards with no color identity const colorlessSymbol = getColorSymbol('C'); return (
); } return (
{colors.map((color) => { const symbolData = getColorSymbol(color); return ( ); })}
); } /** * Single color symbol component for filters */ export function ColorFilterSymbol({ color, isActive, onClick, size = 'md', useSVG = false }) { const symbolData = getColorSymbol(color); return ( ); } /** * Advanced mana cost component with Scryfall analysis */ export function AdvancedManaCost({ cost, showAnalysis = false, useSVG = false }) { const [analysis, setAnalysis] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { async function loadAnalysis() { if (!cost) { setAnalysis(null); setLoading(false); return; } try { const { getManaCostAnalysis } = await import('../lib/mana-symbols'); const analysisData = await getManaCostAnalysis(cost); setAnalysis(analysisData); } catch (error) { console.error('Error analyzing mana cost:', error); setAnalysis(null); } finally { setLoading(false); } } loadAnalysis(); }, [cost]); if (!cost) return null; if (loading) { return
; } if (!analysis) return ; return (
{showAnalysis && (
CMC: {analysis.cmc}
{analysis.colors.length > 0 && (
Colors:
)}
{analysis.colorless && Colorless} {analysis.monocolored && Mono} {analysis.multicolored && Multi}
)}
); } export default ManaCost;