import { useEffect, useState } from "react"; import { Bar, BarChart, CartesianGrid, Cell, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis, } from "recharts"; import { BarChart3, Trophy } from "lucide-react"; import PageHeader from "../components/PageHeader.jsx"; import Donut, { COLORS } from "../components/Donut.jsx"; import EmptyState from "../components/EmptyState.jsx"; import { getByType, getTopPlates, getTrends } from "../api.js"; import { useTheme } from "../hooks/useTheme.js"; const pretty = (t) => t.replace(/_/g, " ").toLowerCase().replace(/\b\w/g, (c) => c.toUpperCase()); // NETRA command-center chart palette (both toggle states stay navy). const NETRA_CHART = { grid: "rgba(132,168,222,0.1)", tick: "#9FB4D2", cursor: "rgba(132,168,222,0.06)", accent: "#3B9EFF", }; const CHART = { light: NETRA_CHART, dark: NETRA_CHART }; const TOOLTIP = { background: "#0c1827", border: "1px solid rgba(132,168,222,0.2)", borderRadius: 10, fontSize: 13, }; export default function Analytics() { const [data, setData] = useState([]); const [trend, setTrend] = useState([]); const [topPlates, setTopPlates] = useState([]); useEffect(() => { getByType() .then((rows) => setData(rows.map((r) => ({ name: pretty(r.type), value: r.count })))) .catch(() => setData([])); getTrends() .then((rows) => setTrend(rows.map((r) => ({ date: r.date.slice(5), count: r.count })))) .catch(() => setTrend([])); getTopPlates().then(setTopPlates).catch(() => setTopPlates([])); }, []); const theme = useTheme(); const c = CHART[theme] || CHART.light; const total = data.reduce((s, d) => s + d.value, 0); if (!data.length) { return ( ); } return ( Share by type {data.map((d, i) => ( {d.name} {d.value} ))} Volume by type {data.map((_, i) => ( ))} Trend over timeviolations per day {trend.length ? ( ) : ( )} Top offendersby plate {topPlates.length ? ( {topPlates.map((p, i) => ( {i + 1} {p.plate} {p.count} ))} ) : ( )} ); }