import React, { useState, useEffect } from 'react'; import { X, Calendar, MapPin, Zap, FileText, User } from 'lucide-react'; import { Outage } from '../../types'; import { backendApi } from '../../services/apiClient'; const WORK_TYPE_LABELS: Record = { absent: 'Отсутствует', planned: 'Плановый', emergency: 'Аварийный', }; interface Props { outageId: number; onClose: () => void; onUpdated?: () => void; } export const OutageCardDetail: React.FC = ({ outageId, onClose, onUpdated }) => { const [outage, setOutage] = useState(null); const [loading, setLoading] = useState(true); const loadOutage = () => { backendApi.getOutage(outageId).then(setOutage).catch(() => setOutage(null)); }; useEffect(() => { setLoading(true); loadOutage(); setLoading(false); }, [outageId]); const handleSetInactive = async () => { if (!outage) return; try { await backendApi.updateOutage(outageId, { active: false }); loadOutage(); onUpdated?.(); } catch (err) { console.error(err); } }; if (loading || !outage) { return (
{loading ? 'Загрузка…' : 'Отключение не найдено'}
); } const formatDate = (s: string) => { const d = new Date(s); return d.toLocaleDateString('ru-RU', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit' }); }; const workTypeLabel = outage.workType ? (WORK_TYPE_LABELS[outage.workType] || outage.workType) : '—'; const classifierText = [outage.category, outage.problemDetail].filter(Boolean).join(' » ') || outage.type || '—'; const address = outage.buildingAddress || outage.buildingId; const endDate = outage.endAt ? new Date(outage.endAt) : null; const now = new Date(); const remainingMs = endDate && endDate > now ? endDate.getTime() - now.getTime() : null; const remainingStr = remainingMs != null ? `${String(Math.floor(remainingMs / 3600000)).padStart(2, '0')}:${String(Math.floor((remainingMs % 3600000) / 60000)).padStart(2, '0')}` : null; return (
{/* Header */}

Отключение №{outage.id}

Дата создания {formatDate(outage.createdAt)}, автор {outage.authorName || 'Администратор'} (вы)

{outage.active && ( Актуально )} {!outage.active && ( Завершено )}
{/* Адрес */}

{address}

{/* Дата проведения работ */}

с {formatDate(outage.startAt)} {outage.endAt && ( <> {' '}до {formatDate(outage.endAt)} {remainingStr && outage.active && ( (осталось {remainingStr}) )} )}

{/* Классификатор */}

{classifierText}

{/* Тип работ */}

{workTypeLabel}

{/* Что случилось */}

{outage.description || '—'}

{/* Что сказать жителю */}

{outage.residentMessage || '—'}

{/* Действия */}
{outage.active && ( )}
); };