'use client'; import { useEffect, useState } from 'react'; import dynamic from 'next/dynamic'; import { Map as MapIcon, Activity } from 'lucide-react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { ChainageSummaryData } from '@/types'; import { projectService } from '@/services/api'; import { getDetectionModeConfig } from '@/constants/detectionModeConfig'; // Dynamically import MapModal with SSR disabled (Leaflet requires window object) const MapModal = dynamic(() => import('@/components/map-modal'), { ssr: false }); interface DetailedSummarySectionProps { projectId: string; videoId: string; show: boolean; detectionType: string; } const DetailedSummarySection = ({ projectId, videoId, show, detectionType, }: DetailedSummarySectionProps) => { const [summaryData, setSummaryData] = useState(null); const [loading, setLoading] = useState(false); const [showMap, setShowMap] = useState(false); useEffect(() => { if (!show || !videoId || !projectId) return; const fetchSummary = async () => { setLoading(true); try { const data = await projectService.getProjectSummaryByVideo(projectId, videoId); setSummaryData(data); } catch (err) { console.error('Failed to fetch summary:', err); } finally { setLoading(false); } }; fetchSummary(); }, [show, videoId, projectId]); if (!show || loading || !summaryData) return null; const modeConfig = getDetectionModeConfig(detectionType); // Flatten all detections for the scrollable list const allDetections: Array<{ detection: any; chainageName: string; packageName: string; }> = []; Object.entries(summaryData.packages || {}).forEach(([packageName, packageData]) => { Object.entries(packageData?.chainages || {}).forEach(([chainageName, chainageData]) => { chainageData?.detections?.forEach((detection) => { allDetections.push({ detection, chainageName, packageName }); }); }); }); return (
Chainages {modeConfig.label} detected
{/* Project Info */}
Project {summaryData.project.name}
{summaryData.project.corridor_name && (
Corridor {summaryData.project.corridor_name}
)}
{/* Packages and Chainages */} {Object.entries(summaryData.packages).map(([packageName, packageData]) => (
{packageName}
{Object.entries(packageData.chainages).map(([chainageName, chainageData]) => (
{chainageName}
{chainageData.detection_count}
))}
))}
All Detections Complete list with GPS coordinates
{allDetections.map(({ detection, chainageName }, idx) => (
{(detection.class || detection.type || '').replace(/_/g, ' ')} #{detection.id} Frame {detection.frame_number}
Chainage: {chainageName}
Confidence:{' '} {(detection.confidence * 100).toFixed(1)}%
GPS: {detection.latitude}, {detection.longitude}
))}
{/* Map Modal */} setShowMap(false)} detections={allDetections.map(({ detection }) => detection)} detectionType={detectionType} />
); }; export default DetailedSummarySection;