"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import type { Decision } from "@/lib/decisions"; // The one-press settle beside a check row (lib/projects/report.mjs `settle`): // a clip patch through the window writer -- "It's deliberate: b repeats a" // (repeatOf), "Move to 12:34" (the clock and the QR back on the clip) -- or a // link check against the sites the QRs open (with `fix`: the dead links whose // fix is known rewritten first -- a Twitch id as v, a Rumble folder id as // its embed id, "Use embed ids"), or a quote check on the durable queue (POST // /api/cli, the registry's `quote-check` row: it transcribes through the // editor, so it queues). The row's `fix` is the same thing from a terminal; // nothing here needs a model. The Inbox's cards press the same buttons (L4). export default function DecisionSettle({ project, settle, token = null, size = "sm", className, lit = false, }: { project: string; settle: NonNullable; token?: string | null; /** The Inbox's card draws it as its primary action: `md`, lit. */ size?: "sm" | "md"; className?: string; /** * A list line's action (the Inbox's card): an OUTLINE at rest, filled only on the lit line (`lit-go`) -- a page * has ONE filled action (visual-audit.spec), so a patch's fix is not filled on every card that offers one. */ lit?: boolean; }) { const router = useRouter(); const [busy, setBusy] = useState(false); const [said, setSaid] = useState(null); const [err, setErr] = useState(null); const run = async () => { setBusy(true); setErr(null); try { const r = settle.kind === "patch" ? await fetch("/api/report/window", { method: "PUT", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, clip: settle.clip, ...settle.patch, ...(token ? { token } : {}) }), }) : settle.kind === "patch-markers" ? await fetch("/api/report/patch-markers", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, file: settle.file }), }) : settle.kind === "quote-check" ? await fetch("/api/cli", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ verb: "quote-check", values: { project, "--clips": settle.clips.join(",") } }), }) : settle.kind === "publish-site" ? await fetch("/api/report/publish-site", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, siteId: settle.siteId }), }) : await fetch("/api/report/links", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, ...(settle.fix ? { fix: true } : {}) }), }); const j = (await r.json().catch(() => ({}))) as { error?: string; verdicts?: { ok: number; dead: unknown[]; unverified: unknown[]; archive: number }; fixed?: { clip: string }[]; notes?: string[]; left?: { label: string | null; after: string }[]; jobId?: string | null; queued?: { qid: string } | null; }; if (!r.ok) { setErr(j.error ?? `HTTP ${r.status}`); return; } if (settle.kind === "check-links" && j.verdicts) { const v = j.verdicts; setSaid(`${j.fixed?.length ? `fixed ${j.fixed.map((f) => f.clip).join(", ")} · ` : ""}${v.ok} of ${v.archive} open · ${v.dead.length} dead · ${v.unverified.length} not verified`); } else if (settle.kind === "patch-markers") { const moved = j.notes?.length ?? 0; const left = j.left ?? []; setSaid( `${moved} marker${moved === 1 ? "" : "s"} moved` + (left.length ? ` · left by hand: ${left.map((l) => `${l.label ? `"${l.label}"` : "a marker"} after ${l.after}`).join(", ")}` : ""), ); } else if (settle.kind === "quote-check") { // The queue runs it (the editor transcribes each clip); the row goes once the check is current. setSaid(`queued${j.queued?.qid ? ` as ${j.queued.qid}` : ""} — ${settle.clips.length} clip${settle.clips.length === 1 ? "" : "s"}; see /jobs`); return; } else if (settle.kind === "publish-site") { // The editor's publish queue runs it; nothing here changes until the deploy lands and a check reads it. setSaid(`queued on the editor's publish queue${j.jobId ? ` (job ${j.jobId})` : ""} — Check links once it is deployed`); return; } else setSaid("saved"); router.refresh(); } catch (e) { setErr(e instanceof Error ? e.message : String(e)); } finally { setBusy(false); } }; return ( {said && !err && ( {said} )} {err && ( {err} )} ); }