'use client' import React from 'react' import { useRouter } from 'next/navigation' import useNavigationStore from '@/app/store/navigationStore' import * as statusColors from '../../lib/statusColors' interface DetectorInfoType { detector_id: number name: string object: string status: string type: string detector_type: string location: string floor: number checked: boolean notifications: Array<{ id: number type: string message: string timestamp: string acknowledged: boolean priority: string }> } interface NotificationDetectorInfoProps { detectorData: DetectorInfoType onClose: () => void } const NotificationDetectorInfo: React.FC = ({ detectorData, onClose }) => { const router = useRouter() const { setSelectedDetector, currentObject } = useNavigationStore() const detectorInfo = detectorData if (!detectorInfo) { return (

Информация о детекторе

Детектор не найден

) } const getStatusColor = (status: string) => { if (status === statusColors.STATUS_COLOR_CRITICAL) return 'text-red-400' if (status === statusColors.STATUS_COLOR_WARNING) return 'text-orange-400' if (status === statusColors.STATUS_COLOR_NORMAL || status === '#4caf50') return 'text-green-400' return 'text-gray-400' } const getPriorityColor = (priority: string) => { switch (priority.toLowerCase()) { case 'high': return 'text-red-400' case 'medium': return 'text-orange-400' case 'low': return 'text-green-400' default: return 'text-gray-400' } } const getPriorityText = (priority: string) => { switch (priority.toLowerCase()) { case 'high': return 'высокий' case 'medium': return 'средний' case 'low': return 'низкий' default: return priority } } const handleReportsClick = () => { const currentUrl = new URL(window.location.href) const objectId = currentUrl.searchParams.get('objectId') || currentObject.id const objectTitle = currentUrl.searchParams.get('objectTitle') || currentObject.title const detectorDataToSet = { detector_id: detectorInfo.detector_id, name: detectorInfo.name, serial_number: '', object: detectorInfo.object, status: detectorInfo.status, checked: detectorInfo.checked, type: detectorInfo.type, detector_type: detectorInfo.detector_type, location: detectorInfo.location, floor: detectorInfo.floor, notifications: detectorInfo.notifications || [] } setSelectedDetector(detectorDataToSet) let reportsUrl = '/reports' const params = new URLSearchParams() if (objectId) params.set('objectId', objectId) if (objectTitle) params.set('objectTitle', objectTitle) if (params.toString()) { reportsUrl += `?${params.toString()}` } router.push(reportsUrl) } const handleHistoryClick = () => { const currentUrl = new URL(window.location.href) const objectId = currentUrl.searchParams.get('objectId') || currentObject.id const objectTitle = currentUrl.searchParams.get('objectTitle') || currentObject.title const detectorDataToSet = { detector_id: detectorInfo.detector_id, name: detectorInfo.name, serial_number: '', object: detectorInfo.object, status: detectorInfo.status, checked: detectorInfo.checked, type: detectorInfo.type, detector_type: detectorInfo.detector_type, location: detectorInfo.location, floor: detectorInfo.floor, notifications: detectorInfo.notifications || [] } setSelectedDetector(detectorDataToSet) let historyUrl = '/history' const params = new URLSearchParams() if (objectId) params.set('objectId', objectId) if (objectTitle) params.set('objectTitle', objectTitle) if (params.toString()) { historyUrl += `?${params.toString()}` } router.push(historyUrl) } const latestNotification = detectorInfo.notifications && detectorInfo.notifications.length > 0 ? detectorInfo.notifications.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime())[0] : null const formatDate = (dateString: string) => { const date = new Date(dateString) return date.toLocaleString('ru-RU', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit' }) } return (

{detectorInfo.name}

{/* Табличка */}
Маркировка по проекту
{detectorInfo.name}
Тип детектора
{detectorInfo.type}
Местоположение
{detectorInfo.location}
Статус
{detectorInfo.status === statusColors.STATUS_COLOR_CRITICAL ? 'Критический' : detectorInfo.status === statusColors.STATUS_COLOR_WARNING ? 'Предупреждение' : detectorInfo.status === statusColors.STATUS_COLOR_NORMAL || detectorInfo.status === '#4caf50' ? 'Нормальный' : 'Неизвестно'}
{latestNotification && (
Последнее уведомление
{formatDate(latestNotification.timestamp)}
Приоритет
{getPriorityText(latestNotification.priority)}
)} {latestNotification && (
Сообщение
{latestNotification.message}
)}
) } export default NotificationDetectorInfo