"use client"; import { useMemo, useState } from "react"; import { useRouter } from "next/navigation"; import { useAuth } from "@/components/AuthProvider"; import { useIncidents } from "@/lib/useIncidents"; import { c2api } from "@/lib/c2api"; import type { IncidentRecord } from "@/lib/types"; import { PageHeader } from "@/components/ui/PageHeader"; import { Card } from "@/components/ui/Card"; import { Button } from "@/components/ui/Button"; import { Badge } from "@/components/ui/Badge"; import { EmptyState } from "@/components/ui/EmptyState"; import { SkeletonCard } from "@/components/ui/Skeleton"; import { severityBadge, severityRank } from "@/lib/severity"; import { TypeBadge } from "@/components/IncidentBadges"; // Severity badge/ordering now lives in lib/severity.ts (shared with CallRow). // `severityBadge()` already returns null for the legacy "unknown" value. type SeverityFilter = "all" | "minor" | "moderate" | "major"; const SEVERITY_FILTERS: { key: SeverityFilter; label: string }[] = [ { key: "all", label: "All" }, { key: "minor", label: "Minor+" }, { key: "moderate", label: "Moderate+" }, { key: "major", label: "Major only" }, ]; const FILTER_THRESHOLD: Record = { all: -1, minor: 1, moderate: 2, major: 3 }; type SortMode = "recent" | "severity"; function fmtTime(iso: string) { try { return new Date(iso).toLocaleString(); } catch { return iso; } } // --------------------------------------------------------------------------- // Rows / cards // --------------------------------------------------------------------------- function IncidentRow({ incident, isAdmin, onResolve }: { incident: IncidentRecord; isAdmin: boolean; onResolve: (id: string) => void; }) { const router = useRouter(); return ( router.push(`/incidents/${incident.incident_id}`)} > {incident.title ?? "—"} {incident.status} {severityBadge(incident.severity)} {incident.call_ids.length} {fmtTime(incident.started_at)} {fmtTime(incident.updated_at)} {isAdmin && incident.status === "active" && ( )} ); } function IncidentCards({ incidents, isAdmin, onResolve }: { incidents: IncidentRecord[]; isAdmin: boolean; onResolve: (id: string) => void; }) { const router = useRouter(); return (
{incidents.map((inc) => ( router.push(`/incidents/${inc.incident_id}`)} >
{inc.status}
{isAdmin && inc.status === "active" && ( )}

{inc.title ?? "—"}

{severityBadge(inc.severity)}

{fmtTime(inc.started_at)} · {inc.call_ids.length} call{inc.call_ids.length !== 1 ? "s" : ""}

))}
); } function IncidentTable({ incidents, isAdmin, onResolve }: { incidents: IncidentRecord[]; isAdmin: boolean; onResolve: (id: string) => void; }) { return ( <>
{incidents.map((inc) => ( ))}
Type Title Status Severity Calls Started Updated
); } function CreateModal({ onClose, onCreate }: { onClose: () => void; onCreate: (body: object) => Promise }) { const [title, setTitle] = useState(""); const [type, setType] = useState("other"); const [summary, setSummary] = useState(""); const [saving, setSaving] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setSaving(true); try { await onCreate({ title, type, summary: summary || null, status: "active" }); onClose(); } finally { setSaving(false); } } return (

Create Incident

setTitle(e.target.value)} className="w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-indigo-500" />