import { useState } from "react"; import type { WidgetProps } from "./types"; import { ReservedControls } from "./ReservedControls"; interface RepairOption { id: string; label: string; archive: "memory" | "evidence"; target_id: string; before: Record; content: Record; } interface Repair { repair_id: string; reason: string; options: RepairOption[]; choice: string | null; status: string; saved: boolean; indexed: boolean; can_apply: boolean; } const statuses: Record = { proposed: "Awaiting your decision. No archive changes have been saved.", applying: "Your choice is recorded. The file update needs recovery; activation is not confirmed.", pending_activation: "Correction saved. Index activation is incomplete; retry to make it available.", active: "Correction saved and active in the archive index.", rejected: "Proposals rejected. No archive changes were made.", superseded: "The archive changed after this correction. Review its current content before proposing another repair.", }; const fieldLabels: Record = { id: "Identity", subject: "Subject", title: "Title", detail: "Detail", scope: "Scope", rationale: "Rationale", question: "Question", sql: "SQL", concepts: "Concepts", dependencies: "Dependencies", links: "Links", family: "Family", kind: "Kind", language: "Language", purposes: "Purposes", applies_to: "Applies to", payload: "Content", provenance: "Source history", review_items: "Review items", }; function Value({ value }: { value: unknown }) { if (value == null) return null; if (Array.isArray(value)) return
    {value.map((item, index) =>
  • )}
; if (typeof value === "object") return
{Object.entries(value).map(([key, item]) =>
{key.replaceAll("_", " ")}
)}
; return {String(value)}; } function Content({ value }: { value: Record }) { return
{Object.entries(fieldLabels).map(([key, label]) => { const item = value[key]; if (item == null || item === "" || (Array.isArray(item) && item.length === 0)) return null; return
{label}
; })}
; } export function ArchiveRepairWidget({ descriptor, onRespond }: WidgetProps) { const repair = descriptor.repair as Repair; const [submitted, setSubmitted] = useState(false); const send = (choice: string) => { if (submitted) return; setSubmitted(true); onRespond({ id: descriptor.id, choices: [choice] }); }; const pending = repair.status === "applying" || repair.status === "pending_activation"; return

Resolve archive conflict

{repair.reason}

{statuses[repair.status] ?? repair.status}

{Boolean(descriptor.error) &&

{String(descriptor.error)}

} {!repair.can_apply &&

An administrator must approve shared archive corrections. You can reject the proposals or continue reviewing this question.

}
{repair.options.map(option =>

{option.label}

{option.archive === "memory" ? "Memory" : "Evidence"} · {option.target_id} {repair.choice === option.id ? " · Selected" : ""}

Before this proposal

Proposed result

{repair.can_apply && !repair.choice && }
)}
{!repair.choice && } {pending && repair.can_apply && repair.choice && } {(repair.choice || !repair.can_apply) && }
{ if (!submitted) { setSubmitted(true); onRespond({ id: descriptor.id, control, text }); } }} />
; }