'use client' import React, { useEffect, useState } from 'react' import { useRouter } from 'next/navigation' import Sidebar from '../ui/Sidebar' import useNavigationStore from '../../app/store/navigationStore' import ChartCard from './ChartCard' import AreaChart from './AreaChart' import BarChart from './BarChart' import DetectorChart from './DetectorChart' const Dashboard: React.FC = () => { const router = useRouter() const { currentObject, setCurrentSubmenu, closeMonitoring, closeFloorNavigation, closeNotifications } = useNavigationStore() const objectId = currentObject?.id const objectTitle = currentObject?.title const [detectorsArray, setDetectorsArray] = useState([]) useEffect(() => { const loadDetectors = async () => { try { const res = await fetch('/api/get-detectors', { cache: 'no-store' }) if (!res.ok) return const payload = await res.json() console.log('[Dashboard] GET /api/get-detectors', { status: res.status, payload }) const detectorsData = payload?.data?.detectors ?? {} const arr = Object.values(detectorsData).filter( (detector: any) => (objectId ? detector.object === objectId : true) ) setDetectorsArray(arr as any[]) } catch (e) { console.error('Failed to load detectors:', e) } } loadDetectors() }, [objectId]) const handleBackClick = () => { router.push('/objects') } interface DetectorData { detector_id: number name: string object: string status: string type: string location: string floor: number checked?: boolean notifications: Array<{ id: number type: string message: string timestamp: string acknowledged: boolean priority: string }> } // Статусы const statusCounts = detectorsArray.reduce((acc: { critical: number; warning: number; normal: number }, detector: DetectorData) => { if (detector.status === '#b3261e') acc.critical++ else if (detector.status === '#fd7c22') acc.warning++ else if (detector.status === '#00ff00') acc.normal++ return acc }, { critical: 0, warning: 0, normal: 0 }) const handleNavigationClick = () => { closeMonitoring() closeFloorNavigation() closeNotifications() setCurrentSubmenu(null) router.push('/navigation') } return (

Объект {objectId?.replace('object_', '')}

Период
{/* Карты-графики */}
{/* Список детекторов */}

Тренды

Месяц
{/* Таблица */}
{detectorsArray.map((detector: DetectorData) => ( ))}
Детектор Статус Местоположение Проверен
{detector.name}
{detector.status === '#b3261e' ? 'Критическое' : detector.status === '#fd7c22' ? 'Предупреждение' : 'Норма'}
{detector.location} {detector.checked ? (
Да
) : ( Нет )}
{/* Статы */}
{detectorsArray.length}
Всего
{statusCounts.normal}
Норма
{statusCounts.warning}
Предупреждения
{statusCounts.critical}
Критические
{/* Графики с аналитикой */}
) } export default Dashboard