'use client' import React from 'react' interface DetectorType { detector_id: number name: string serial_number: string object: string status: string checked: boolean type: string detector_type: string location: string floor: number notifications?: Array<{ id: number type: string message: string timestamp: string acknowledged: boolean priority: string }> } interface DetectorMenuProps { detector: DetectorType isOpen: boolean onClose: () => void getStatusText: (status: string) => string compact?: boolean anchor?: { left: number; top: number } | null } const DetectorMenu: React.FC = ({ detector, isOpen, onClose, getStatusText, compact = false, anchor = null }) => { if (!isOpen) return null // Получаем самую свежую временную метку из уведомлений const latestTimestamp = (() => { const list = detector.notifications ?? [] if (!Array.isArray(list) || list.length === 0) return null const dates = list.map(n => new Date(n.timestamp)).filter(d => !isNaN(d.getTime())) if (dates.length === 0) return null dates.sort((a, b) => b.getTime() - a.getTime()) return dates[0] })() const formattedTimestamp = latestTimestamp ? latestTimestamp.toLocaleString('ru-RU', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }) : 'Нет данных' const rawDetectorTypeCode = (detector.detector_type || '').toUpperCase() const deriveCodeFromType = (): string => { const t = (detector.type || '').toLowerCase() if (!t) return '' if (t.includes('инклинометр')) return 'GA' if (t.includes('тензометр')) return 'PE' if (t.includes('гидроуров')) return 'GLE' return '' } const effectiveDetectorTypeCode = rawDetectorTypeCode || deriveCodeFromType() const detectorTypeLabelMap: Record = { GA: 'Инклинометр', PE: 'Тензометр', GLE: 'Гидроуровень', } const displayDetectorTypeLabel = detectorTypeLabelMap[effectiveDetectorTypeCode] || '—' const DetailsSection: React.FC<{ compact?: boolean }> = ({ compact = false }) => (
{compact ? ( <>
Маркировка по проекту
{detector.name}
Тип детектора
{displayDetectorTypeLabel}
Местоположение
{detector.location}
Статус
{getStatusText(detector.status)}
Временная метка
{formattedTimestamp}
Этаж
{detector.floor}
Серийный номер
{detector.serial_number}
) : ( <>
Маркировка по проекту
{detector.name}
Тип детектора
{displayDetectorTypeLabel}
Местоположение
{detector.location}
Статус
{getStatusText(detector.status)}
Временная метка
{formattedTimestamp}
Серийный номер
{detector.serial_number}
)}
) if (compact && anchor) { return (
Датч.{detector.name}
{getStatusText(detector.status)}
) } return (

Датч.{detector.name}

) } export default DetectorMenu