"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { buttonVariants } from "@/components/ui/button"; import { startTakeJob } from "./NewTakePanel"; import PlayLink from "./PlayLink"; // What a take offers (a saved version, or a legacy take): play it read-only, // open it in the draft to edit it (L3: every edit lands in the draft), render // it (a draft's first render, or a walked take's again), and make it the cut. // The Takes page's cards draw this; each button is the CLI's own command run // the app's way: // // Play · Open in draft /projects/

/play?take= · /projects/

/takes//open // = umtool takes open

// Render full / Render 60 s POST /api/report/takes/make { rebuild, window } // = umtool take

--id --rebuild [--full | --at 0 --dur 60] // Make this the cut POST /api/report/takes/promote // = umtool take

--id --promote [--anyway] export default function TakeActions({ project, take, draft, openHref, edited, compact = false, }: { project: string; take: string; draft: boolean; /** Open in draft (OpenInDraftPage): it asks, saves the draft first when it has edits, copies the take in. */ openHref: string | null; /** Edited by the walk since its render (or never rendered). */ edited: boolean; compact?: boolean; }) { const router = useRouter(); const [ready, setReady] = useState(false); const [busy, setBusy] = useState(false); const [said, setSaid] = useState(null); const [stale, setStale] = useState(null); const [done, setDone] = useState(null); useEffect(() => setReady(true), []); const render = async (window: "full" | { at: number; dur: number }) => { setBusy(true); setSaid(null); const r = await startTakeJob({ project, rebuild: take, window }); setBusy(false); setSaid(r.error ?? "rendering — the job is on the jobs bar"); }; const promote = async (anyway: boolean) => { setBusy(true); setSaid(null); try { const r = await fetch("/api/report/takes/promote", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, take, anyway }), cache: "no-store", }); const j = (await r.json().catch(() => ({}))) as { error?: string; errors?: string[]; stale?: boolean; historyHref?: string; clips?: number }; if (r.status === 409 && j.stale) setStale(j.error ?? "the project changed since this take was made"); else if (!r.ok) setSaid(j.errors?.join("; ") ?? j.error ?? `HTTP ${r.status}`); else { setStale(null); setDone(j.historyHref ?? ""); router.refresh(); } } finally { setBusy(false); } }; const off = !ready || busy; const size = compact ? "sm" : "md"; return (

{openHref && ( Open in draft )} {stale && ( {stale}. )} {done !== null && ( This take is the cut now — the Cut tab's Undo last edit takes it back.{" "} {done && ( Revisions )} )} {said && ( {said} )}
); }