"use client"; import { PrototypeToolDialog } from "@prototype/components/platform-ui/prototype-tool-dialog"; import { Button } from "@prototype/components/ui/button"; import { Input } from "@prototype/components/ui/input"; import { Label } from "@prototype/components/ui/label"; import { PROTOTYPE_BRIEF_FIELD_BORDER_CLASS } from "@prototype/components/prototypes/prototype-brief-field"; import { buildLinkSourceCopyText } from "@prototype/lib/prototypes/link-source-prompt"; import useCopyToClipboard from "@prototype/lib/use-copy-to-clipboard"; import { useEffect, useId, useState } from "react"; import { toast } from "sonner"; export type PrototypeLinkSourceModalProps = { open: boolean; onOpenChange: (open: boolean) => void; currentSourcePath?: string; }; export function PrototypeLinkSourceModal({ open, onOpenChange, currentSourcePath, }: PrototypeLinkSourceModalProps) { const pathFieldId = useId(); const [sourcePath, setSourcePath] = useState(""); const [isCopying, setIsCopying] = useState(false); const { copy, icon, isCopied } = useCopyToClipboard(); const canCopy = sourcePath.trim().length > 0; const isUpdate = Boolean(currentSourcePath?.trim()); useEffect(() => { if (!open) { setSourcePath(""); return; } setSourcePath(currentSourcePath?.trim() ?? ""); }, [open, currentSourcePath]); const handleCopy = async () => { if (!canCopy || isCopying) return; setIsCopying(true); try { await copy( buildLinkSourceCopyText({ sourcePath, currentSourcePath, }), ); } catch { toast.error("Copy error", { description: "Failed to copy link source prompt", }); } finally { setIsCopying(false); } }; return ( { void handleCopy(); }} aria-label="Copy link source prompt" > {isCopied ? "Copied prompt" : isCopying ? "Copying…" : "Copy prompt"} {icon} } >
setSourcePath(event.target.value)} placeholder="ex. ../my-product-repo or /Users/you/projects/my-app" className={PROTOTYPE_BRIEF_FIELD_BORDER_CLASS} />
); }