"use client"; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend } from "recharts"; export interface DailyAggregate { localDate: string; avgWait: number | null; maxWait: number | null; avgFastLane: number | null; maxFastLane: number | null; uptimePct: number; sampleCount: number; } interface Props { data: DailyAggregate[]; hasFastLane: boolean; mode: "regular" | "fastLane"; } function shortDay(localDate: string): string { // "2026-05-29" → "May 29" const [, m, d] = localDate.split("-"); const month = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][parseInt(m, 10)]; return `${month} ${parseInt(d, 10)}`; } export default function WeeklyStatsChart({ data, hasFastLane, mode }: Props) { const showFastLane = mode === "fastLane" && hasFastLane; const avgColor = showFastLane ? "#ff4d8d" : "#4ade80"; const maxColor = showFastLane ? "#ff4d8d" : "#22c55e"; const maxFill = showFastLane ? "#3d0f22" : "#0a1a0d"; const chartData = data.map((d) => ({ day: shortDay(d.localDate), avg: showFastLane ? (d.avgFastLane !== null ? Math.round(d.avgFastLane) : null) : (d.avgWait !== null ? Math.round(d.avgWait) : null), max: showFastLane ? d.maxFastLane : d.maxWait, })); return (
{ if (!active || !payload || payload.length === 0) return null; return (
{label}
{payload.map((entry) => { const color = entry.dataKey === "max" ? maxColor : avgColor; const v = entry.value; const display = v === null || v === undefined ? "—" : `${v} min`; return (
{entry.name} : {display}
); })}
); }} /> value === "Max" ? {value} : value } />
); }