import { ReactNode } from 'react'; import { clsx } from 'clsx'; import Surface from './Surface'; interface MetricCardProps { label: string; value?: number | string | null; icon?: ReactNode; helper?: string; changeRate?: number | null; disabled?: boolean; className?: string; } const formatValue = (value?: number | string | null) => { if (value === null || value === undefined) return '통계 API 연결 전'; if (typeof value === 'number') return value.toLocaleString(); return value; }; export default function MetricCard({ label, value, icon, helper, changeRate, disabled = false, className, }: MetricCardProps) { const hasChange = typeof changeRate === 'number'; const isPositive = hasChange && changeRate >= 0; return (
{label} {icon}

{formatValue(value)}

{(helper || hasChange) && (

{hasChange ? `${isPositive ? '+' : ''}${changeRate.toFixed(1)}%` : helper}

)}
); }