import { useEffect, useState } from "react"; import { AlertTriangle, Check, FileCheck2, Loader2, ScanLine, ScanText, Wand2, } from "lucide-react"; const STAGES = [ { key: "prep", label: "Enhance", icon: Wand2 }, { key: "detect", label: "Detect", icon: ScanLine }, { key: "classify", label: "Classify", icon: AlertTriangle }, { key: "plates", label: "Read plates", icon: ScanText }, { key: "evidence", label: "Evidence", icon: FileCheck2 }, ]; export default function Pipeline({ analyzing, result }) { const [active, setActive] = useState(0); useEffect(() => { if (!analyzing) return; const id = setInterval(() => setActive((a) => (a + 1) % STAGES.length), 520); return () => clearInterval(id); }, [analyzing]); const stat = (key) => { if (!result) return null; const plates = result.violations.filter((v) => v.license_plate).length; return { prep: `${result.quality.score}/100`, detect: `${result.detections} users`, classify: `${result.violations.length} flags`, plates: `${plates} read`, evidence: "ready", }[key]; }; const done = result && !analyzing; return (
{STAGES.map((s, i) => { const isActive = analyzing && i === active; const Icon = done ? Check : isActive ? Loader2 : s.icon; return (
{s.label} {done ? stat(s.key) : " "}
{i < STAGES.length - 1 && }
); })}
); }