import React from 'react'; import { Card } from '../ui/card'; import { ArrowUp, ArrowDown } from 'lucide-react'; interface StatCardProps { label: string; value: string | number; icon: React.ReactNode; trend?: string | number; // String like "+12%" or raw number color?: 'cyan' | 'magenta' | 'lime' | 'gold' | 'red'; sparklineData?: number[]; } export const StatCard: React.FC = ({ label, value, icon, trend, color = 'cyan', sparklineData, }) => { const colorMap = { cyan: 'text-kodo-cyan', magenta: 'text-kodo-magenta', lime: 'text-kodo-lime', gold: 'text-kodo-gold', red: 'text-kodo-red', }; const bgMap = { cyan: 'bg-kodo-steel/10', magenta: 'bg-kodo-magenta/10', lime: 'bg-kodo-lime/10', gold: 'bg-kodo-gold/10', red: 'bg-kodo-red/10', }; const renderSparkline = (data: number[]) => { if (!data || data.length < 2) return null; const min = Math.min(...data); const max = Math.max(...data); const range = max - min || 1; const width = 100; const height = 40; const points = data .map((d, i) => { const x = (i / (data.length - 1)) * width; const y = height - ((d - min) / range) * height; return `${x},${y}`; }) .join(' '); return ( ); }; const isPositive = typeof trend === 'string' ? !trend.startsWith('-') : (trend || 0) >= 0; const trendValue = typeof trend === 'number' ? `${Math.abs(trend)}%` : trend; return (

{label}

{value}

{icon}
{trend && (
{isPositive ? ( ) : ( )} {trendValue}{' '} vs last period
)}
{sparklineData && (
{renderSparkline(sparklineData)}
)}
); };