"use client" import { Popup } from "react-map-gl/mapbox" import { Badge } from "@/app/_components/ui/badge" import { Card } from "@/app/_components/ui/card" import { Separator } from "@/app/_components/ui/separator" import { Button } from "@/app/_components/ui/button" import { MapPin, AlertTriangle, Calendar, Clock, Bookmark, Navigation, X, FileText, Shield } from "lucide-react" import { IDistanceResult } from "@/app/_utils/types/crimes" import { ScrollArea } from "@/app/_components/ui/scroll-area" import { Skeleton } from "@/app/_components/ui/skeleton" import { INearestUnits } from "@/app/(pages)/(admin)/dashboard/crime-management/units/action" interface IncidentPopupProps { longitude: number latitude: number onClose: () => void incident: { id: string category?: string description?: string date?: Date | string district?: string district_id?: string } nearestUnit?: INearestUnits[] isLoadingNearestUnit?: boolean } export default function IncidentPopup({ longitude, latitude, onClose, incident, nearestUnit = [], isLoadingNearestUnit = false }: IncidentPopupProps) { const formatDate = (date?: Date | string) => { if (!date) return "Unknown date" return new Date(date).toLocaleDateString() } const formatTime = (date?: Date | string) => { if (!date) return "Unknown time" return new Date(date).toLocaleTimeString() } // Format distance to be more readable const formatDistance = (meters: number) => { if (meters < 1000) { return `${meters.toFixed(0)} m`; } else { return `${(meters / 1000).toFixed(2)} km`; } } return (
{/* Custom close button */}

{incident.category || "Unknown Incident"}

{incident.description && (

{incident.description}

)}
{incident.district && (

District

{incident.district}

)} {incident.date && ( <>

Date

{formatDate(incident.date)}

Time

{formatTime(incident.date)}

)}
{/* NearestUnit to police nearestUnits section */}

Nearby Units

{isLoadingNearestUnit ? (
) : nearestUnit.length > 0 ? (
{nearestUnit.map((unit) => (

{unit.name || "Unknown"} ({unit.type || "Unknown type"})

{unit.address || "No address"}

{formatDistance(unit.distance_meters)}
))}
) : (

No nearby units found

)}

Coordinates: {latitude.toFixed(6)}, {longitude.toFixed(6)}

ID: {incident.id}

) }