"use client"; import { useEffect, useRef, useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { edgeClock } from "@/lib/report/clipEditorModel.mjs"; // Two of the clip editor's edits on the CUT rather than the clip (UI notes // 2026-10-30, items 2 and 11): // // Flash-forward this span… a tight copy of the selected seconds put // earlier (after an entry, or into a section), its // attribution and locks copied, as a repeat of // this clip -- or moved out of it (POST // /api/report/clip-editor { op: "flash-forward" }, // manifest.mjs flashForward; `umtool timeline

// flash-forward`) // Add to trailer the selection (else the cut) as a trailer beat, // in the cut's order (POST /api/report/trailer-beats, // trailerBeats.mjs; `umtool trailer-beats

add`) type Section = { index: number; words: string; clips: string[] }; type Entry = { id: string; type: string }; export function FlashForwardForm({ project, clipId, span, busy, onCancel, onGo, }: { project: string; clipId: string; span: { from: number; to: number }; busy: boolean; onCancel: () => void; onGo: (body: Record) => void; }) { const [entries, setEntries] = useState([]); const [sections, setSections] = useState([]); const [where, setWhere] = useState<"after" | "section">("after"); const [after, setAfter] = useState(""); const [section, setSection] = useState(""); const [move, setMove] = useState(false); // A choice made before the sections came back is the person's: the default never overrides it. const touched = useRef(false); useEffect(() => { let live = true; void fetch(`/api/report/timeline?project=${encodeURIComponent(project)}`, { cache: "no-store" }) .then((r) => r.json()) .then((j: { timeline?: Entry[]; sections?: Section[] }) => { if (!live) return; const tl = Array.isArray(j.timeline) ? j.timeline : []; setEntries(tl); const secs = Array.isArray(j.sections) ? j.sections : []; setSections(secs); // A flash-forward goes EARLIER: by default, the start of the section this clip is in. const mine = secs.find((s) => s.clips.includes(clipId)); if (mine && secs.length > 1 && !touched.current) { setWhere("section"); setSection(String(mine.index)); } }) .catch(() => {}); return () => { live = false; }; }, [project, clipId]); const input = "rounded border border-[var(--color-line)] bg-[var(--color-ink)] px-1.5 py-0.5 text-[11px] text-[var(--color-text)] outline-none focus:border-[var(--color-sel)]"; const mineAt = entries.findIndex((e) => e.id === clipId); const go = () => onGo({ op: "flash-forward", clip: clipId, from: span.from, to: span.to, move, ...(where === "section" && section !== "" ? { section: Number(section), position: "start" } : { after: after || null }), }); return (

flash-forward {clipId} {edgeClock(span.from)}–{edgeClock(span.to)} ({(span.to - span.from).toFixed(1)} s)
{sections.length > 1 && ( )}
the title, date, cite, QR link, quote, speakers and locks go with it
); } /** Add the span to the trailer's beats; says where it landed and the running length. */ export async function addToTrailer(project: string, clipId: string, span: { from: number; to: number }): Promise<{ ok: boolean; message: string }> { const read = await fetch(`/api/report/trailer-beats?project=${encodeURIComponent(project)}`, { cache: "no-store" }).then((r) => r.json()).catch(() => ({})); const r = await fetch("/api/report/trailer-beats", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, token: read.token ?? null, op: "add", beat: { id: clipId, start: span.from, end: span.to } }), }); const j = (await r.json().catch(() => ({}))) as { error?: string; rows?: { id?: string; start?: number; n: number }[]; total?: number; limit?: number; over?: boolean }; if (!r.ok) return { ok: false, message: j.error ?? `HTTP ${r.status}` }; const row = j.rows?.find((x) => x.id === clipId && Math.abs((x.start ?? 0) - span.from) < 0.01); const clock = (s: number) => `${Math.floor(s / 60)}:${(s % 60).toFixed(1).padStart(4, "0")}`; return { ok: true, message: `Added to the trailer${row ? ` as beat ${row.n}` : ""}: ${clock(j.total ?? 0)} of ${clock(j.limit ?? 140)}${j.over ? " — OVER the limit" : ""}`, }; }