/* 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 (
);
}
// 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 (