"use client" import { useEffect, useState } from "react" import dynamic from "next/dynamic" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Loader2, MapPin, AlertTriangle, RectangleHorizontal } from "lucide-react" import { fetchAllDetections, type Detection } from "@/lib/api" // Dynamically import the map to avoid SSR issues with Leaflet const DashboardMapContent = dynamic( () => import("./dashboard-map-content"), { ssr: false, loading: () => (
) } ) interface DashboardMapProps { className?: string } export function DashboardMap({ className }: DashboardMapProps) { const [detections, setDetections] = useState([]) const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { const loadDetections = async () => { try { setIsLoading(true) setError(null) const data = await fetchAllDetections() setDetections(data) } catch (err) { console.error("Failed to load detections:", err) setError("Failed to load detection data") } finally { setIsLoading(false) } } loadDetections() }, []) // Filter detections with valid GPS coordinates const validDetections = detections.filter(d => d.latitude && d.longitude) // Count potholes and signboards const potholeCount = validDetections.filter(d => d.type?.toLowerCase().includes("pothole") || d.class?.toLowerCase().includes("pothole") ).length const signboardCount = validDetections.length - potholeCount return (
Detection Map

{isLoading ? "Loading..." : `${validDetections.length} detections with GPS coordinates`}

{/* Compact Color Legend */}
Potholes ({potholeCount})
Signboards ({signboardCount})
{isLoading ? (
) : error ? (

{error}

) : validDetections.length === 0 ? (

No detections with GPS coordinates found

Process some videos to see detections on the map

) : ( )}
) }