import React from 'react'; import { motion } from 'framer-motion'; import { Car, Truck, Bike, User, Bus, CheckCircle, AlertTriangle, XCircle, AlertCircle } from 'lucide-react'; const ROAD_META = [ { label: 'Road A', accent: '#3b82f6', bg: 'rgba(37,99,235,0.12)', border: '#1e3a70', bar: 'linear-gradient(90deg,#1d4ed8,#60a5fa)' }, { label: 'Road B', accent: '#06b6d4', bg: 'rgba(6,182,212,0.12)', border: '#164e63', bar: 'linear-gradient(90deg,#0e7490,#22d3ee)' }, { label: 'Road C', accent: '#8b5cf6', bg: 'rgba(139,92,246,0.12)', border: '#3b1f7a', bar: 'linear-gradient(90deg,#6d28d9,#a78bfa)' }, { label: 'Road D', accent: '#f59e0b', bg: 'rgba(245,158,11,0.12)', border: '#78350f', bar: 'linear-gradient(90deg,#b45309,#fbbf24)' }, ]; const CONGESTION = [ { max: 3, label: 'LOW', Icon: CheckCircle, bg: 'rgba(34,197,94,0.12)', color: '#86efac', border: 'rgba(34,197,94,0.3)' }, { max: 8, label: 'MEDIUM', Icon: AlertCircle, bg: 'rgba(245,158,11,0.12)', color: '#fcd34d', border: 'rgba(245,158,11,0.3)' }, { max: 15, label: 'HIGH', Icon: AlertTriangle,bg: 'rgba(249,115,22,0.12)', color: '#fdba74', border: 'rgba(249,115,22,0.3)' }, { max: Infinity, label: 'CRITICAL', Icon: XCircle, bg: 'rgba(239,68,68,0.15)', color: '#fca5a5', border: 'rgba(239,68,68,0.35)' }, ]; const VEHICLE_TYPES = { car: { label: 'Cars', color: '#60a5fa', Icon: Car }, bus: { label: 'Buses', color: '#fbbf24', Icon: Bus }, truck: { label: 'Trucks', color: '#fb923c', Icon: Truck }, motorbike: { label: 'Motorbikes', color: '#c084fc', Icon: Bike }, bicycle: { label: 'Bicycles', color: '#4ade80', Icon: Bike }, person: { label: 'Persons', color: '#f472b6', Icon: User }, }; const DetectionResultCard = ({ roadIndex = 0, data, preview = null }) => { const meta = ROAD_META[roadIndex] || ROAD_META[0]; const count = data?.count || 0; const vehicles = data?.vehicles || []; const confidence = data?.confidence ? (data.confidence * 100).toFixed(0) : 0; const cong = CONGESTION.find(l => count <= l.max) || CONGESTION[3]; const CongIcon = cong.Icon; const typeCounts = {}; vehicles.forEach(v => { typeCounts[v] = (typeCounts[v] || 0) + 1; }); const detectedTypes = Object.entries(typeCounts).filter(([, n]) => n > 0); return ( {/* Image or Placeholder */}
{preview ? ( {meta.label} ) : (
)}
{/* Road Badge */}
{meta.label}
{/* Confidence */}
{confidence}% conf
{/* Body */}
{/* Count + Congestion */}
Total Vehicles
{count}
{/* Congestion Badge */}
{cong.label}
{/* Vehicle Types */} {detectedTypes.length > 0 ? (
{detectedTypes.map(([type, n]) => { const tv = VEHICLE_TYPES[type]; if (!tv) return null; const TVIcon = tv.Icon; return (
{tv.label}
{n}
); })}
) : (
No vehicles detected
)} {/* Density Bar */}
); }; export default DetectionResultCard;