"use client"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { trailerHref } from "@/lib/hrefs"; // New reel on the Trailer page: a name (promo/-beats.json), empty or a // copy of another reel's beats, through the beats' one writer. export default function NewReel({ project, reels }: { project: string; reels: string[] }) { const router = useRouter(); const [open, setOpen] = useState(false); const [name, setName] = useState(""); const [from, setFrom] = useState(""); const [error, setError] = useState(null); const make = async () => { setError(null); const r = await fetch("/api/report/trailer-beats", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, reel: name, op: "new-reel", name, ...(from ? { from } : {}) }), }); const j = await r.json().catch(() => ({})); if (!r.ok) { setError(String(j.error ?? `HTTP ${r.status}`)); return; } setOpen(false); setName(""); setFrom(""); router.push(trailerHref(project, { reel: name })); router.refresh(); }; if (!open) { return ( ); } return ( setName(e.target.value.toLowerCase())} onKeyDown={(e) => e.key === "Enter" && void make()} className="w-28 rounded border border-[var(--color-line)] bg-[var(--color-ink)] px-1.5 py-0.5 font-mono text-[11px] text-[var(--color-text)]" /> {error && {error}} ); }