import { useMemo } from 'react'; interface SparklineProps { timestamps: number[]; periodDays: number; } /** * Mini bar-chart SVG affichant l'activité journalière sur la période. * Utilise les timestamps déjà en mémoire — aucune requête supplémentaire. */ export function Sparkline({ timestamps, periodDays }: SparklineProps) { const buckets = useMemo(() => { if (timestamps.length === 0) return []; const n = periodDays === 1 ? 24 : Math.min(periodDays, 30); const now = Date.now(); const start = now - periodDays * 864e5; const step = (periodDays * 864e5) / n; const counts = new Array(n).fill(0); for (const ts of timestamps) { const i = Math.floor((ts - start) / step); if (i >= 0 && i < n) counts[i]++; } return counts; }, [timestamps, periodDays]); if (buckets.length === 0) return null; const n = buckets.length; const max = Math.max(...buckets, 1); const W = 100; const H = 32; const barW = W / n; const gap = barW * 0.18; return (
{periodDays === 1 ? '0h' : 'J-' + periodDays} {periodDays === 1 ? 'maintenant' : 'aujourd\'hui'}
); }