import React from 'react' import { AlertTriangle, AlertCircle, Clock, Shield, MapPin, ChevronLeft, ChevronRight, FileText, Calendar } from 'lucide-react' import { Card, CardContent } from "@/app/_components/ui/card" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/app/_components/ui/tabs" import { Badge } from "@/app/_components/ui/badge" import { Button } from "@/app/_components/ui/button" import { formatMonthKey, getIncidentSeverity, getMonthName, getTimeAgo } from "@/app/_utils/common" import { SystemStatusCard } from "../components/system-status-card" import { IncidentCard } from "../components/incident-card" interface SidebarIncidentsTabProps { crimeStats: any formattedDate: string formattedTime: string location: string selectedMonth?: number | "all" selectedYear: number selectedCategory: string | "all" getTimePeriodDisplay: () => string paginationState: Record handlePageChange: (monthKey: string, direction: 'next' | 'prev') => void handleIncidentClick: (incident: any) => void activeIncidentTab: string setActiveIncidentTab: (tab: string) => void } export function SidebarIncidentsTab({ crimeStats, formattedDate, formattedTime, location, selectedMonth = "all", selectedYear, selectedCategory, getTimePeriodDisplay, paginationState, handlePageChange, handleIncidentClick, activeIncidentTab, setActiveIncidentTab }: SidebarIncidentsTabProps) { const topCategories = crimeStats.categoryCounts ? Object.entries(crimeStats.categoryCounts) .sort((a: any, b: any) => (b[1] as number) - (a[1] as number)) .slice(0, 4) .map(([type, count]: [string, unknown]) => { const countAsNumber = count as number; const percentage = Math.round(((countAsNumber) / crimeStats.totalIncidents) * 100) || 0 return { type, count: countAsNumber, percentage } }) : [] return ( <> {/* Enhanced info card */}
{formattedDate}
{formattedTime}
{location}
{crimeStats.totalIncidents || 0} incidents reported {selectedMonth !== 'all' ? ` in ${getMonthName(Number(selectedMonth))}` : ` in ${selectedYear}`}
{/* Enhanced stat cards */}
} statusColor="text-green-400" updatedTime={getTimePeriodDisplay()} bgColor="bg-gradient-to-br from-sidebar-accent/30 to-sidebar-accent/20" borderColor="border-sidebar-border" /> } statusColor="text-amber-400" updatedTime="Last 30 days" bgColor="bg-gradient-to-br from-sidebar-accent/30 to-sidebar-accent/20" borderColor="border-sidebar-border" /> 0 ? topCategories[0].type : "None"} statusIcon={} statusColor="text-green-400" bgColor="bg-gradient-to-br from-sidebar-accent/30 to-sidebar-accent/20" borderColor="border-sidebar-border" /> } statusColor="text-purple-400" updatedTime="Affected areas" bgColor="bg-gradient-to-br from-sidebar-accent/30 to-sidebar-accent/20" borderColor="border-sidebar-border" />
{/* Nested tabs for Recent and History */}

Incident Reports

Recent History
{/* Recent Incidents Tab Content */} {crimeStats.recentIncidents.length === 0 ? (

{selectedCategory !== "all" ? `No ${selectedCategory} incidents found` : "No recent incidents reported"}

Try adjusting your filters or checking back later

) : (
{crimeStats.recentIncidents.slice(0, 6).map((incident: any) => ( handleIncidentClick(incident)} /> ))}
)}
{/* History Incidents Tab Content */} {crimeStats.availableMonths && crimeStats.availableMonths.length === 0 ? (

{selectedCategory !== "all" ? `No ${selectedCategory} incidents found in the selected period` : "No incidents found in the selected period"}

Try adjusting your filters

) : (
Showing incidents from {crimeStats.availableMonths.length} {crimeStats.availableMonths.length === 1 ? 'month' : 'months'} {selectedCategory !== "all" ? selectedCategory : "All Categories"}
{crimeStats.availableMonths.map((monthKey: string) => { const incidents = crimeStats.incidentsByMonthDetail[monthKey] || [] const pageSize = 5 const currentPage = paginationState[monthKey] || 0 const totalPages = Math.ceil(incidents.length / pageSize) const startIdx = currentPage * pageSize const endIdx = startIdx + pageSize const paginatedIncidents = incidents.slice(startIdx, endIdx) if (incidents.length === 0) return null return (

{formatMonthKey(monthKey)}

{incidents.length} incident{incidents.length !== 1 ? 's' : ''}
{paginatedIncidents.map((incident: any) => ( handleIncidentClick(incident)} showTimeAgo={false} /> ))}
{totalPages > 1 && (
Page {currentPage + 1} of {totalPages}
)}
) })}
)}
) }