"use client"; import React, { useCallback, useEffect, useState } from "react"; import { Plus, Copy, Pencil } from "lucide-react"; import { errorMessage } from "@/lib/utils"; import { useSiteSettings } from "@/contexts/SiteSettingsContext"; import { apiV2Data } from "@/lib/apiV2"; type Status = "open" | "contained" | "closed"; type Breach = { id: string; title: string; status: Status; discoveredAt: string; occurredAt: string | null; description: string; dataAffected: string; peopleAffected: number | null; whoAffected: string | null; consequences: string | null; actionsTaken: string | null; adviceToPeople: string | null; causedBy: string | null; regulatorNotifiedAt: string | null; peopleNotifiedAt: string | null; createdBy: { name: string } | null; createdAt: string; }; type Form = Record<"title" | "description" | "dataAffected" | "whoAffected" | "consequences" | "actionsTaken" | "adviceToPeople" | "causedBy" | "discoveredAt" | "occurredAt" | "peopleAffected", string>; const EMPTY: Form = { title: "", description: "", dataAffected: "", whoAffected: "", consequences: "", actionsTaken: "", adviceToPeople: "", causedBy: "", discoveredAt: "", occurredAt: "", peopleAffected: "" }; const STATUS: Record = { open: { label: "Open", tone: "bg-red-50 text-red-700" }, contained: { label: "Contained", tone: "bg-amber-50 text-amber-800" }, closed: { label: "Closed", tone: "bg-gray-100 text-gray-600" }, }; const inputCls = "w-full border rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-brand-500"; const fmt = (d: string | null) => (d ? new Date(d).toLocaleString(undefined, { day: "numeric", month: "short", year: "numeric", hour: "2-digit", minute: "2-digit" }) : "—"); // wants local "YYYY-MM-DDTHH:mm". const toLocal = (d: string | null) => { if (!d) return ""; const x = new Date(d); return new Date(x.getTime() - x.getTimezoneOffset() * 60000).toISOString().slice(0, 16); }; function BreachForm({ initial, onSave, onCancel, busy }: { initial: Form; onSave: (f: Form) => void; onCancel: () => void; busy: boolean }) { const [f, setF] = useState(initial); const field = (k: keyof Form, label: string, opts: { rows?: number; required?: boolean; type?: string; placeholder?: string } = {}) => (