"use client"; import { ToolbarIconButton } from "@prototype/components/platform-ui/toolbar-icon-button"; import { Button } from "@prototype/components/ui/button"; import { Input } from "@prototype/components/ui/input"; import { Label } from "@prototype/components/ui/label"; import { buildAddReferenceDocCopyText, defaultReferenceDocsConfigPath, isValidReferenceDocInput, type PrototypeReferenceDoc, } from "@prototype/lib/prototypes/reference-docs"; import { usePrototypeReviewOptional } from "@prototype/lib/prototypes/prototype-review-context"; import useCopyToClipboard from "@prototype/lib/use-copy-to-clipboard"; import { cn } from "@prototype/lib/utils"; import { ChevronDown, ExternalLink, Plus } from "lucide-react"; import { useId, useState } from "react"; const REFERENCE_DOC_CONTENT_FIELD_CLASS = "field-sizing-content min-h-[5rem] w-full resize-y rounded-md border border-[var(--tool-chrome-border)] bg-[var(--tool-chrome-surface-muted)] px-2.5 py-2 text-sm text-[var(--tool-chrome-text)] leading-relaxed shadow-none outline-none placeholder:text-[var(--tool-chrome-text-muted)] focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-offset-0"; function ReferenceDocItem({ doc }: { doc: PrototypeReferenceDoc }) { const [expanded, setExpanded] = useState(false); const hasContent = doc.content.trim().length > 0; return (
  • {doc.name} {hasContent ? ( ) : null}
    {hasContent ? (

    {doc.content}

    ) : null}
  • ); } type PrototypeReferenceDocsProps = { slug?: string; docs?: PrototypeReferenceDoc[]; configFilePath?: string; className?: string; }; export function PrototypeReferenceDocs({ slug: slugProp, docs: docsProp, configFilePath: configFilePathProp, className, }: PrototypeReferenceDocsProps) { const review = usePrototypeReviewOptional(); const slug = slugProp ?? review?.slug; const docs = docsProp ?? review?.referenceDocs ?? []; const configFilePath = configFilePathProp ?? review?.referenceDocsConfigFilePath ?? (slug ? defaultReferenceDocsConfigPath(slug) : undefined); const nameFieldId = useId(); const linkFieldId = useId(); const contentFieldId = useId(); const [showForm, setShowForm] = useState(false); const [name, setName] = useState(""); const [link, setLink] = useState(""); const [content, setContent] = useState(""); const { copy, icon, isCopied } = useCopyToClipboard(); const canCopy = Boolean(slug) && isValidReferenceDocInput(name, link, content); const handleCopyPrompt = () => { if (!slug || !canCopy) return; const origin = typeof window !== "undefined" ? window.location.origin : undefined; copy( buildAddReferenceDocCopyText({ slug, name, link, content, existingDocs: docs, configFilePath, origin, }), ); }; return (
    Reference docs setShowForm((current) => !current)} aria-label={showForm ? "Cancel adding doc" : "Add doc"} aria-expanded={showForm} >
    {showForm ? (
    setName(event.target.value)} placeholder="Design spec" />
    setLink(event.target.value)} placeholder="https://docs.google.com/..." />