"use client"; import { useEffect, useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { GAP_CUE_CORNERS, GAP_CUE_MIN, GAP_CUE_PLACES, GAP_OWN_CORNERS, GAP_REASON_MAX, gapCueText, gapMarkOn, gapWhyWord, type GapCue } from "yt-dlp-transcript-common/lib/report/gapCue.mjs"; import type { GapEditor } from "./useGapEditor"; // --------------------------------------------------------------------------- // THE MARK AT A GAP'S JOIN, SET ON THE BENCH (lane gap-cue, slice 1b; common // lib/report/gapCue.mjs is the rule). Under the gaps' tools, in Cut mode: // // the picked gap (a click on its band) its seconds, how it shows (a skip: // fast-forward is not built yet), its own mark (as the // clip's, on, off), what it was cut for (its mark says it: // "» 26 s · dead air"), a few words of its own instead, its // own corner (a stream's layout can change inside a clip), // what its mark will say, Remove // the clip's the mark at its joins (as the project's, on, off), the // shortest gap marked, the corner, the label, the border // (accent: the deck's accent colour, or a #rrggbb) // // Every control writes at once through the window writer -- `gapEdit` for the // gap (useGapEditor's editPicked: an undo point, and the bench's Undo), // `gapCue` for the clip (an undo point) -- the same writes as their CLI twins, // named on each control. // --------------------------------------------------------------------------- const sel = "rounded border border-[var(--color-line)] bg-[var(--color-panel-2)] px-1 py-0.5 text-[11px] text-[var(--color-text)] disabled:opacity-60"; const onOff = (v: boolean) => (v ? "on" : "off"); const CORNER_WORDS: Record = { auto: "the layout's", tl: "top left", tr: "top right", bl: "bottom left", br: "bottom right" }; const PLACE_WORDS: Record = { footage: "over the footage", deck: "in the deck" }; export default function GapCueTools({ gap, cue, project, own, busy, fmt, writeCue, borderColor = null, hasGaps, }: { gap: GapEditor; /** The clip's settings, its own over the project's (clipGapCueOf). */ cue: GapCue; /** The project's (gapCueOf(render), the look preset under it): what the clip's "as the project's" means. */ project: GapCue; /** The clip's own `gapCue` block, as saved (null: none). */ own: Partial | null; busy: boolean; fmt: (t: number) => string; /** Write the clip's `gapCue` patch (a key null drops it); resolves whether it was written. */ writeCue: (patch: Record) => Promise; /** The border's colour as the render resolves it (common gapCueBorderOf): shown beside the field. */ borderColor?: string | null; hasGaps: boolean; }) { const g = gap.picked; // The two typed fields: drafted, written on Enter or leaving them. const [min, setMin] = useState(own?.min === undefined ? "" : String(own.min)); const [label, setLabel] = useState(own?.label ?? ""); const [border, setBorder] = useState(own?.border ?? ""); const [reason, setReason] = useState(g?.reason ?? ""); useEffect(() => setMin(own?.min === undefined ? "" : String(own.min)), [own?.min]); useEffect(() => setLabel(own?.label ?? ""), [own?.label]); useEffect(() => setBorder(own?.border ?? ""), [own?.border]); useEffect(() => setReason(g?.reason ?? ""), [g?.from, g?.to, g?.reason]); if (!hasGaps) return null; const commitMin = () => { const v = min.trim(); const was = own?.min === undefined ? "" : String(own.min); if (v === was) return; void writeCue({ min: v === "" ? null : Number(v) }); }; const commitLabel = () => { if (label === (own?.label ?? "")) return; void writeCue({ label: label === "" ? null : label }); }; const commitBorder = () => { const v = border.trim(); if (v === (own?.border ?? "")) return; void writeCue({ border: v === "" ? null : v }); }; const commitReason = () => { if (!g || reason.trim() === (g.reason ?? "")) return; void gap.editPicked({ reason: reason.trim() === "" ? null : reason.trim() }); }; const len = g ? g.to - g.from : 0; const at = g ? ((g.from + g.to) / 2).toFixed(2) : ""; return (
{g && ( gap {fmt(g.from)}–{fmt(g.to)} ({len.toFixed(2)} s) shows as skip · fast-forward: not built yet gap.reason=${at}:, gap.reason=${at}: drops them)`} onChange={(e) => setReason(e.target.value)} onBlur={commitReason} onKeyDown={(e) => { if (e.key === "Enter") commitReason(); }} /> {gapMarkOn(cue, g) && len >= cue.min && ( {gapCueText(len, cue.label, gapWhyWord(g))} )} {gapMarkOn(cue, g) && len < cue.min && ( under {cue.min} s: no mark )} )} mark at joins
); }