import { useRef } from 'react'; import type { PeriodStats } from '../services/DataService'; interface StatsPanelProps { stats: PeriodStats | null; loading: boolean; periodDays: number; source: 'live' | 'mock'; } const MEDALS = ['🥇', '🥈', '🥉']; function StatCard({ label, value, sub, delta }: { label: string; value: string; sub?: string; delta?: 'up' | 'down' | null }) { return (

{label}

{value} {delta === 'up' && ↑} {delta === 'down' && ↓}

{sub &&

{sub}

}
); } export function StatsPanel({ stats, loading, periodDays, source }: StatsPanelProps) { const periodLabel = periodDays === 1 ? '24 dernières heures' : `${periodDays} derniers jours`; const prevStats = useRef(null); // Calcule le delta d'une valeur par rapport au refresh précédent function delta(current: number, prevMap: Map, key: string) { const prev = prevMap.get(key); if (prev === undefined) return null; if (current > prev) return ↑; if (current < prev) return ↓; return null; } // Construit une map volume précédent par ville const prevCityVolume = new Map( (prevStats.current?.topCities ?? []).map((c) => [c.name, c.volume]) ); const prevVolume = prevStats.current?.totalVolume ?? null; const prevTxCount = prevStats.current?.transactionCount ?? null; // Mémorise les stats après le rendu if (stats && !loading) prevStats.current = stats; const geoPct = stats && stats.transactionCount > 0 ? Math.round((stats.geoCount / stats.transactionCount) * 100) : null; return ( ); }