"use client";
import Link from "next/link";
import { useEffect, useState } from "react";
import { clipBenchHref, ingredientHref, postBenchHref } from "@/lib/hrefs";
import ClipBench, { type ClipBenchData } from "../ClipBench";
import PostBench from "../PostBench";
import type { PostBenchData } from "@/lib/report/postBenchData";
import IntroRow from "../report/IntroEditor";
import TeaserInspector from "../inspector/TeaserInspector";
import PostItemInspector from "../inspector/PostItemInspector";
import TitleInspector from "../inspector/TitleInspector";
import ProvenanceInspector from "../inspector/ProvenanceInspector";
import LedgerInspector from "../inspector/LedgerInspector";
import LinksInspector from "../inspector/LinksInspector";
import StillInspector from "../inspector/StillInspector";
import type { PlayEntry } from "../review/PlayCut";
// ---------------------------------------------------------------------------
// THE INSPECTOR (umtool redesign L7a): one column, chosen by the selected block.
//
// a clip the clip bench's work column (ClipBench, layout "inspector": the window row, the
// instrument -- the waveform, its handles, the gaps -- and the cue rail), its life cycle
// a post item the post item panel (L6: excerpt, media, recording) and the post bench (PostBench,
// layout "inspector": its attachments' trims, sound, crop, its hold)
// a card/teaser the teaser panel (L6)
// the intro the intro editor (L2)
// nothing the project's panels (L6): title, provenance, ledger, links, a still
//
// Every panel is the one its page draws, mounted here unchanged (no fork), and every write lands in the
// draft with its own undo point (the workspace's Undo takes it back). Each reads its own state from its
// own route; the workspace reads the draft again when one announces a write (MANIFEST_CHANGED).
// ---------------------------------------------------------------------------
type Loaded = { key: string; state: "loading" | "ready" | "error"; data?: T; error?: string };
function useJson(url: string | null): Loaded | null {
const [got, setGot] = useState | null>(null);
useEffect(() => {
if (!url) {
setGot(null);
return;
}
let live = true;
setGot({ key: url, state: "loading" });
void (async () => {
try {
const r = await fetch(url, { cache: "no-store" });
const j = (await r.json().catch(() => ({}))) as T & { error?: string };
if (!live) return;
if (!r.ok) setGot({ key: url, state: "error", error: j.error ?? `HTTP ${r.status}` });
else setGot({ key: url, state: "ready", data: j });
} catch (e) {
if (live) setGot({ key: url, state: "error", error: e instanceof Error ? e.message : String(e) });
}
})();
return () => {
live = false;
};
}, [url]);
return got && got.key === url ? got : url ? { key: url, state: "loading" } : null;
}
function Head({ kind, id, children }: { kind: string; id?: string | null; children?: React.ReactNode }) {
return (