'use client' import React, { useState } from 'react' import { Incident, INCIDENT_SEVERITY_INFO, INCIDENT_STATUS_INFO, INCIDENT_CATEGORY_INFO } from '@/lib/sdk/incidents/types' import { CountdownTimer } from './CountdownTimer' const STATUS_TRANSITIONS: Record = { detected: { label: 'Bewertung starten', nextStatus: 'assessment' }, assessment: { label: 'Eindaemmung starten', nextStatus: 'containment' }, containment: { label: 'Meldepflicht pruefen', nextStatus: 'notification_required' }, notification_required: { label: 'Gemeldet', nextStatus: 'notification_sent' }, notification_sent: { label: 'Behebung starten', nextStatus: 'remediation' }, remediation: { label: 'Abschliessen', nextStatus: 'closed' }, closed: null } export function IncidentDetailDrawer({ incident, onClose, onStatusChange, onDeleted, }: { incident: Incident onClose: () => void onStatusChange: () => void onDeleted?: () => void }) { const [isChangingStatus, setIsChangingStatus] = useState(false) const [isDeleting, setIsDeleting] = useState(false) const handleDeleteIncident = async () => { if (!window.confirm(`Incident "${incident.title}" wirklich löschen?`)) return setIsDeleting(true) try { const res = await fetch(`/api/sdk/v1/incidents/${incident.id}`, { method: 'DELETE' }) if (!res.ok) throw new Error(`Fehler: ${res.status}`) onDeleted ? onDeleted() : onClose() } catch (err) { console.error('Löschen fehlgeschlagen:', err) alert('Löschen fehlgeschlagen.') } finally { setIsDeleting(false) } } const severityInfo = INCIDENT_SEVERITY_INFO[incident.severity] const statusInfo = INCIDENT_STATUS_INFO[incident.status] const categoryInfo = INCIDENT_CATEGORY_INFO[incident.category] const transition = STATUS_TRANSITIONS[incident.status] const handleStatusChange = async (newStatus: string) => { setIsChangingStatus(true) try { const res = await fetch(`/api/sdk/v1/incidents/${incident.id}/status`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ status: newStatus }) }) if (!res.ok) { throw new Error(`Fehler: ${res.status}`) } onStatusChange() } catch (err) { console.error('Status-Aenderung fehlgeschlagen:', err) } finally { setIsChangingStatus(false) } } return (
{/* Backdrop */}
{/* Drawer */}
{/* Header */}
{severityInfo.label} {statusInfo.label}
{/* Title */}

{incident.referenceNumber}

{incident.title}

{/* Status Transition */} {transition && (

Naechster Schritt:

)} {/* Details Grid */}

Kategorie

{categoryInfo.icon} {categoryInfo.label}

Schweregrad

{severityInfo.label}

Status

{statusInfo.label}

Entdeckt am

{new Date(incident.detectedAt).toLocaleString('de-DE')}

{incident.detectedBy && (

Entdeckt von

{incident.detectedBy}

)} {incident.assignedTo && (

Zugewiesen an

{incident.assignedTo}

)}

Betroffene Personen (geschaetzt)

{incident.estimatedAffectedPersons.toLocaleString('de-DE')}

{/* Description */} {incident.description && (

Beschreibung

{incident.description}

)} {/* Affected Systems */} {incident.affectedSystems && incident.affectedSystems.length > 0 && (

Betroffene Systeme

{incident.affectedSystems.map((sys, idx) => ( {sys} ))}
)} {/* 72h Countdown */}

72h-Meldefrist

{/* Delete */}
) }