import { useState } from 'react'; import type { Incident, IncidentStage, Locale } from '../types'; import { formatTime, translations } from '../lib/i18n'; import { Check, Clock, History, Warning } from './Icons'; export function Incidents({ incidents, locale, compact = false }: { incidents: Incident[]; locale: Locale; compact?: boolean }) { const t = translations[locale]; const stages: Record = { detected: t.stageDetected, reported: t.stageReported, investigating: t.stageInvestigating, identified: t.stageIdentified, monitoring: t.stageMonitoring, resolved: t.stageResolved, postmortem: t.stagePostmortem }; const [filter, setFilter] = useState('all'); const filtered = incidents.filter(incident => filter === 'all' || (filter === 'active' ? !incident.resolvedAt : Boolean(incident.resolvedAt))); const visible = compact ? filtered.slice(0, 3) : filtered; return <> {!compact &&
{(['all', 'active', 'resolved'] as const).map(key => )}
} {!visible.length ?

{filter === 'all' ? t.noIncidents : t.noFiltered}

{t.noIncidentsDescription}

:
{visible.map(incident => { const latest = incident.updates.at(-1); const stage = incident.resolvedAt ? 'resolved' : latest?.stage || (incident.source === 'monitor' ? 'detected' : 'reported'); return
{incident.resolvedAt ? : }{stages[stage]}

{incident.title[locale]}

{latest?.message[locale] || incident.message[locale]}

{incident.impact &&
{incident.resolvedAt ? t.impactPast : t.impactTitle}

{incident.impact[locale]}

}
{t.duration}: {incident.resolvedAt ? `${Math.max(1, Math.round((incident.resolvedAt - incident.startedAt) / 60000))} ${t.minutes}` : t.ongoing}{incident.scope === 'scenario' ? t.scenarioTitle : incident.source === 'monitor' ? t.automated : t.teamUpdate}
{t.timeline}{t.updates}: {incident.updates.length}
    {incident.updates.map(update =>
  1. {update.source === 'monitor' ? t.automated : t.teamUpdate}

    {stages[update.stage]}

    {update.message[locale]}

  2. )}
; })}
} ; }