"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 (
{kind} {id ? {id} : null} {children}
); } const Waiting = ({ what }: { what: string }) =>

reading {what}…

; const Failed = ({ error }: { error: string }) =>

{error}

; function ClipInspector({ project, entry }: { project: string; entry: PlayEntry }) { const url = `/api/report/bench?${new URLSearchParams({ project, clip: entry.id, order: "cut" }).toString()}`; const got = useJson<{ data: ClipBenchData }>(url); return ( <> {/* The clip's recording across its life cycle (lane L5): found, downloaded, … published. */} {entry.video && entry.sourceChannel && ( Life cycle )} Full bench {entry.quote ?

“{entry.quote}”

: null}
{!got || got.state === "loading" ? : got.state === "error" ? : }
); } function PostInspector({ project, entry }: { project: string; entry: PlayEntry }) { const url = `/api/report/post-bench?${new URLSearchParams({ project, id: entry.id }).toString()}`; const got = useJson(url); const d = got?.state === "ready" ? got.data! : null; return ( <> Full bench
{/* The excerpt picked by selection, media on/off, "use my recording" (L6). */} {!got || got.state === "loading" ? ( ) : got.state === "error" ? ( ) : ( d && ( ) )}
); } export default function WorkspaceInspector({ project, entry, hasLedger, hasClips, introWritten, readOnly = false, openInDraft = null, }: { project: string; entry: PlayEntry | null; hasLedger: boolean; hasClips: boolean; introWritten: unknown; /** The workspace's read-only flag (readOnly.ts): a saved version on screen -- no panel that writes the draft. */ readOnly?: boolean; openInDraft?: string | null; }) { if (readOnly) { return ( <>

A saved version is read-only: its panels would write the draft.{" "} {openInDraft && ( Open in draft )}

); } if (entry?.type === "clip") return ; if (entry?.type === "post") return ; if (entry?.type === "teaser") { return ( <>
); } if (entry?.type === "intro") { return ( <>
); } if (entry) { // A card the build draws (a chapter card, a video entry): nothing of its own to inspect here yet. return ( <>

{entry.heading ? `“${entry.heading}”. ` : ""}A {entry.type} is edited on the cut as a list (Piece ▾).

); } // Nothing selected: the project's own panels. return ( <>
{hasClips && } {hasLedger && }
); }