"use client"; 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 { useState } from "react"; const TYPE_COLORS: Record = { fire: "bg-red-900 text-red-300", police: "bg-blue-900 text-blue-300", ems: "bg-yellow-900 text-yellow-300", accident: "bg-orange-900 text-orange-300", other: "bg-gray-800 text-gray-300", }; const SEVERITY_COLORS: Record = { major: "bg-red-950 text-red-400", moderate: "bg-orange-950 text-orange-400", minor: "bg-gray-800 text-gray-400", }; function severityBadge(severity: string | null | undefined) { if (!severity || severity === "unknown") return null; const cls = SEVERITY_COLORS[severity] ?? "bg-gray-800 text-gray-400"; return ( {severity} ); } function typeBadge(type: string | null) { const cls = TYPE_COLORS[type ?? "other"] ?? TYPE_COLORS.other; return ( {type ?? "other"} ); } function fmtTime(iso: string) { try { return new Date(iso).toLocaleString(); } catch { return iso; } } function IncidentRow({ incident, isAdmin, onResolve }: { incident: IncidentRecord; isAdmin: boolean; onResolve: (id: string) => void; }) { const router = useRouter(); return ( router.push(`/incidents/${incident.incident_id}`)} > {typeBadge(incident.type)} {incident.title ?? "—"} {incident.status} {severityBadge(incident.severity)} {incident.call_ids.length} {fmtTime(incident.started_at)} {fmtTime(incident.updated_at)} {isAdmin && incident.status === "active" && ( )} ); } 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" />