"use client" import { Card, CardContent, CardHeader, CardTitle } from "@/app/_components/ui/card" import { Skeleton } from "@/app/_components/ui/skeleton" import DistrictLayer, { type DistrictFeature } from "./layers/district-layer" import MapView from "./map" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/app/_components/ui/select" import { Button } from "@/app/_components/ui/button" import { AlertCircle, FilterX } from "lucide-react" import { getMonthName } from "@/app/_utils/common" import { useCrimeMapHandler } from "@/app/(pages)/(admin)/dashboard/crime-management/crime-overview/_handlers/crime-map-handlers" import { useState } from "react" import { CrimePopup } from "./pop-up" import CrimeMarker, { type CrimeIncident } from "./markers/crime-marker" import { MapLegend } from "./controls/map-legend" import MapFilterControl from "./controls/map-filter-control" const months = [ { value: "1", label: "January" }, { value: "2", label: "February" }, { value: "3", label: "March" }, { value: "4", label: "April" }, { value: "5", label: "May" }, { value: "6", label: "June" }, { value: "7", label: "July" }, { value: "8", label: "August" }, { value: "9", label: "September" }, { value: "10", label: "October" }, { value: "11", label: "November" }, { value: "12", label: "December" }, ] export default function CrimeMap() { // Set default year to 2024 instead of "all" const [selectedYear, setSelectedYear] = useState(2024) const [selectedMonth, setSelectedMonth] = useState("all") const [selectedDistrict, setSelectedDistrict] = useState(null) const [selectedIncident, setSelectedIncident] = useState(null) const [showLegend, setShowLegend] = useState(true) const { availableYears, yearsLoading, yearsError, crimes, crimesLoading, crimesError, refetchCrimes } = useCrimeMapHandler(selectedYear, selectedMonth) // Extract all incidents from all districts for marker display const allIncidents = crimes?.flatMap((district) => district.incidents.map((incident) => ({ id: incident.id, timestamp: incident.timestamp, description: incident.description, status: incident.status, category: incident.category, type: incident.type, address: incident.address, latitude: incident.latitude, longitude: incident.longitude, })), ) || [] // Handle district click const handleDistrictClick = (feature: DistrictFeature) => { setSelectedDistrict(feature) } // Handle incident marker click const handleIncidentClick = (incident: CrimeIncident) => { setSelectedIncident(incident) } // Apply filters const applyFilters = () => { refetchCrimes() } // Reset filters const resetFilters = () => { setSelectedYear(2024) setSelectedMonth("all") refetchCrimes() } // Determine the title based on filters const getMapTitle = () => { let title = `${selectedYear}` if (selectedMonth !== "all") { title += ` - ${getMonthName(Number(selectedMonth))}` } return title } // Create map filter controls - now MapView will only render these in fullscreen mode const mapFilterControls = ( ) return ( Crime Map {getMapTitle()}
{/* Regular (non-fullscreen) controls */}
{crimesLoading ? (
) : crimesError ? (

Failed to load crime data. Please try again later.

) : (
{/* Show the legend regardless of fullscreen state if showLegend is true */} {showLegend && } {/* District Layer with crime data */} {/* Display all crime incident markers */} {/* {allIncidents?.map((incident) => ( ))} */} {/* Popup for selected incident */} {selectedIncident && ( setSelectedIncident(null)} crime={selectedIncident} /> )}
)}
) }