import { useState } from "react"; import { videoStylesApi } from "../../api/endpoints"; import type { VideoStyleItem } from "../../api/types"; import { errorMessage, Modal } from "../ui"; /** A custom video style: guidance for how the script is written. Draft it with AI from a description, or write it. * Pass `style` to edit an existing one. */ export function StyleCreator({ style, onClose, onSaved }: { style?: VideoStyleItem; onClose: () => void; onSaved: (s: VideoStyleItem) => void; }) { const [prompt, setPrompt] = useState(""); const [name, setName] = useState(style?.name ?? ""); const [guidance, setGuidance] = useState(style?.guidance ?? ""); const [method, setMethod] = useState<"manual" | "ai">("manual"); const [busy, setBusy] = useState<"draft" | "save" | null>(null); const [error, setError] = useState(null); async function draft() { setBusy("draft"); setError(null); try { const d = await videoStylesApi.aiDraft(prompt.trim()); setName(d.name); setGuidance(d.guidance); setMethod("ai"); } catch (e) { setError(errorMessage(e)); } finally { setBusy(null); } } async function save() { setBusy("save"); setError(null); try { const saved = style?.custom_id ? await videoStylesApi.update(style.custom_id, { name: name.trim(), guidance: guidance.trim(), version: style.version ?? 0 }) : await videoStylesApi.create({ name: name.trim(), guidance: guidance.trim(), creation_method: method, source_prompt: method === "ai" ? prompt.trim() : undefined }); onSaved(saved); } catch (e) { setError(errorMessage(e)); setBusy(null); } } return (
{!style && (
Describe the style (optional)