"use client"; import { useState } from "react"; /* The one thing on the console that cannot be undone. Owner only (the server checks too), the * facility's exact name typed, and a live code from the operator's own second factor. */ export default function Danger({ facilityId, name, owner, totpEnabled }: { facilityId: string; name: string; owner: boolean; totpEnabled: boolean }) { const [open, setOpen] = useState(false); const [confirm, setConfirm] = useState(""); const [code, setCode] = useState(""); const [err, setErr] = useState(""); const [busy, setBusy] = useState(false); async function submit(e: React.FormEvent) { e.preventDefault(); setBusy(true); setErr(""); try { const r = await fetch("/api/ops/controls", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ action: "facility.delete", facilityId, confirm, code }) }); const j = await r.json().catch(() => ({})); if (!r.ok) { setErr(j.error || "That didn’t work."); return; } window.location.assign("/ops/facilities?deleted=1"); } catch { setErr("No connection — check the network and try again."); } finally { setBusy(false); } } const label: React.CSSProperties = { display: "block", fontSize: 11, fontWeight: 700, letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--color-neutral-600)", marginBottom: 4 }; if (!owner) return