"use client"; import { PrototypeToolDialog } from "@prototype/components/platform-ui/prototype-tool-dialog"; import { PROTOTYPE_BRIEF_FIELD_BORDER_CLASS, PrototypeBriefTextarea, } from "@prototype/components/prototypes/prototype-brief-field"; import { Button } from "@prototype/components/ui/button"; import { Input } from "@prototype/components/ui/input"; import { Label } from "@prototype/components/ui/label"; import { buildCreateStarterScreenCopyText } from "@prototype/lib/prototypes/create-starter-screen-prompt"; import { readBriefFieldValue } from "@prototype/lib/prototypes/read-brief-field-value"; import { useTrackEvent } from "@prototype/lib/prototypes/telemetry/prototype-telemetry-context"; import { useWorkspaceProfile } from "@prototype/lib/prototypes/use-workspace-profile"; import useCopyToClipboard from "@prototype/lib/use-copy-to-clipboard"; import { useEffect, useId, useState } from "react"; import { toast } from "sonner"; export type PrototypeCreateStarterScreenModalProps = { open: boolean; onOpenChange: (open: boolean) => void; starterScreensPagePath?: string; sourcePath?: string; }; export function PrototypeCreateStarterScreenModal({ open, onOpenChange, starterScreensPagePath, sourcePath, }: PrototypeCreateStarterScreenModalProps) { const titleFieldId = useId(); const routeFieldId = useId(); const referenceHtmlFieldId = useId(); const [title, setTitle] = useState(""); const [route, setRoute] = useState(""); const [referenceHtml, setReferenceHtml] = useState(""); const { copy, icon, isCopied } = useCopyToClipboard(); const workspaceProfile = useWorkspaceProfile(); const track = useTrackEvent(); const [isCopying, setIsCopying] = useState(false); const canCopy = title.trim().length > 0 && route.trim().length > 0 && referenceHtml.trim().length > 0; useEffect(() => { if (!open) { setTitle(""); setRoute(""); setReferenceHtml(""); } }, [open]); const handleCopy = async () => { if (isCopying) return; const titleValue = readBriefFieldValue(titleFieldId); const routeValue = readBriefFieldValue(routeFieldId); const referenceHtmlValue = readBriefFieldValue(referenceHtmlFieldId); const hasAllFields = titleValue.trim().length > 0 && routeValue.trim().length > 0 && referenceHtmlValue.trim().length > 0; if (!hasAllFields) { toast.error("Missing fields", { description: "Fill in title, route, and reference HTML before copying.", }); return; } setIsCopying(true); try { const origin = typeof window !== "undefined" ? window.location.origin : undefined; await copy( buildCreateStarterScreenCopyText({ title: titleValue, route: routeValue, referenceHtml: referenceHtmlValue, sourcePath, origin, starterScreensPagePath, workspaceProfile, }), ); track("modal.prompt_copied", { modal: "create-starter-screen" }); } catch { toast.error("Copy error", { description: "Failed to copy starter screen prompt", }); } finally { setIsCopying(false); } }; return ( { void handleCopy(); }} aria-label="Copy starter screen brief and prompt" > {isCopied ? "Copied prompt" : isCopying ? "Copying…" : "Copy prompt"} {icon} } >
setTitle(event.target.value)} placeholder="ex. Team Settings Overview" className={PROTOTYPE_BRIEF_FIELD_BORDER_CLASS} />
setRoute(event.target.value)} placeholder="ex. /project/default/settings/team" className={PROTOTYPE_BRIEF_FIELD_BORDER_CLASS} spellCheck={false} />
setReferenceHtml(event.target.value)} placeholder="Paste rendered HTML from the source app (Inspect → Copy outerHTML)…" scrollable aria-label="Reference HTML" spellCheck={false} className="font-mono text-xs leading-relaxed" />
); }