import { Popup } from 'react-map-gl/mapbox'; import { useState, useEffect } from 'react'; import { X } from 'lucide-react'; import { DistrictFeature } from './layers/district-layer'; import { useQuery } from "@tanstack/react-query"; import { Skeleton } from "@/app/_components/ui/skeleton"; import { getCrimeRateInfo } from "@/app/_utils/common"; import { CrimeIncident } from './markers/crime-marker'; interface MapPopupProps { longitude: number latitude: number onClose: () => void children: React.ReactNode title?: string } export function MapPopup({ longitude, latitude, onClose, children, title }: MapPopupProps) { return (
{title &&

{title}

} {children}
) } // Function to fetch district details - this would typically be implemented // to fetch more detailed information about a district const getDistrictDetails = async (districtId: string, year?: string, month?: string) => { // This would be an API call to get district details // For now, we'll return mock data return { category_breakdown: [ { category: "Theft", count: 12 }, { category: "Assault", count: 5 }, { category: "Vandalism", count: 8 } ] }; }; export function DistrictPopup({ longitude, latitude, onClose, district, year, month }: { longitude: number latitude: number onClose: () => void district: DistrictFeature year?: string month?: string }) { const { data: districtDetails, isLoading } = useQuery({ queryKey: ['district-details', district.id, year, month], queryFn: () => getDistrictDetails(district.id, year, month), enabled: !!district.id }); const rateInfo = getCrimeRateInfo(district.level); return (

{district.name}

{district.number_of_crime !== undefined && (
Total Incidents: {district.number_of_crime}
)} {district.level && (
Crime Rate: {rateInfo.text}
)} {year && (
Year: {year} {month && <>, Month: {month}}
)} {isLoading ? (
) : districtDetails?.category_breakdown && districtDetails.category_breakdown.length > 0 ? (

Crime Categories:

{districtDetails.category_breakdown.map((cat, idx) => (
{cat.category} {cat.count}
))}
) : null}
District ID: {district.id}
) } export function CrimePopup({ longitude, latitude, onClose, crime }: { longitude: number latitude: number onClose: () => void crime: CrimeIncident }) { return (
Type: {crime.category}
{crime.timestamp && (
Date: {new Date(crime.timestamp).toLocaleDateString()}
)} {crime.description && (
Description:

{crime.description}

)}
ID: {crime.id}
) }