"use client"; import { useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; // COPY SHARE LINE (lane output-modes): a clip's platform page at the moment and // its archive moment (GET /api/report/share-line, lib/report/shareLine.mjs), // copied to the clipboard and shown -- the line stays readable beside the // button, so a browser that refuses the clipboard still has it to select. // On the take panel (a take's first clip) and on Play (the clip on screen). // The CLI twin: `umtool share [] [--take ]`. type Line = { clip: string; seconds: number; platform: string | null; archive: string | null; text: string }; export default function CopyShareLine({ project, clip = null, take = null, size = "sm", testid = "", }: { project: string; clip?: string | null; take?: string | null; size?: "sm" | "md"; testid?: string; }) { const [state, setState] = useState<"idle" | "busy" | "copied" | "shown" | "error">("idle"); const [line, setLine] = useState(null); const [error, setError] = useState(null); const copy = async () => { setState("busy"); setError(null); try { const q = new URLSearchParams({ project, ...(clip ? { clip } : {}), ...(take ? { take } : {}) }); const r = await fetch(`/api/report/share-line?${q}`, { cache: "no-store" }); const j = (await r.json().catch(() => ({}))) as Line & { error?: string }; if (!r.ok) throw new Error(j.error ?? `HTTP ${r.status}`); setLine(j); if (!j.text) { setState("shown"); return; } try { await navigator.clipboard.writeText(j.text); setState("copied"); } catch { // The clipboard refused (no permission, not a secure context): the line is shown to select. setState("shown"); } } catch (e) { setError(e instanceof Error ? e.message : String(e)); setState("error"); } }; return ( {line && ( {line.text || `${line.clip}: no platform page or archive to link`} )} {error && ( {error} )} ); }