import React, { useState } from 'react'; import { useAppContext } from '../../context/AppContext.tsx'; import CameraCountCard from './CameraCountCard.tsx'; import { VideoIcon } from '../icons/Icons.tsx'; import AccordionItem from './AccordionItem.tsx'; const LocationCountBreakdown: React.FC = () => { const { aggregatedCounts } = useAppContext(); const [openAccordions, setOpenAccordions] = useState>(() => { const initialState: Record = {}; if (aggregatedCounts.length > 0) { const firstLocation = aggregatedCounts[0]; initialState[firstLocation.locationId] = true; if (firstLocation.coops.length > 0) { const firstCoop = firstLocation.coops[0]; initialState[firstCoop.coopId] = true; // Open all floors within that first coop by default as they don't have sub-items firstCoop.floors.forEach((floor) => { initialState[floor.floorId] = true; }); } } return initialState; }); const handleToggle = (id: string) => { setOpenAccordions((prev) => ({ ...prev, [id]: !prev[id] })); }; const expandAll = () => { const allIds: Record = {}; aggregatedCounts.forEach((location) => { allIds[location.locationId] = true; location.coops.forEach((coop) => { allIds[coop.coopId] = true; coop.floors.forEach((floor) => { allIds[floor.floorId] = true; }); }); }); setOpenAccordions(allIds); }; const collapseAll = () => { setOpenAccordions({}); }; if (aggregatedCounts.length === 0) { return (

Rincian Populasi per Lokasi

Tidak Ada Data Penghitungan

Tidak ada kamera online yang melaporkan data penghitungan saat ini.

); } return (

Rincian Populasi per Lokasi

{aggregatedCounts.map((location) => (
{location.coops.map((coop) => (
{coop.floors.map((floor) => (
{floor.cameras.map((lc) => ( ))}
))}
))}
))}
); }; export default LocationCountBreakdown;