{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "prompt-library",
  "title": "Prompt Library Block",
  "description": "A library of reusable AI prompts: categories, search, popular, recent and favorite sorting, cards that highlight {{variables}}, a side panel that builds a form from those variables with a live preview, Copy and Use in chat, and a New prompt form that finds variables as you type.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/prompt-library/prompt-library.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface PromptItem {\n  id: string;\n  title: string;\n  category: string;\n  description?: string;\n  /** Use {{name}} for fill-in variables. */\n  body: string;\n  uses?: number;\n  author?: string;\n  /** Higher is newer; used for the Recent sort. */\n  created?: number;\n}\n\nexport interface PromptLibraryProps {\n  title?: string;\n  prompts?: PromptItem[];\n  categories?: string[];\n  /** Called with the filled prompt when someone presses Use in chat. */\n  onUse?: (text: string, prompt: PromptItem) => void;\n  onCreate?: (prompt: PromptItem) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", faint: \"rgba(245,244,241,0.38)\", card: \"#121212\", raised: \"#161616\", border: \"rgba(255,255,255,0.09)\", hover: \"rgba(255,255,255,0.05)\", chip: \"rgba(255,255,255,0.06)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", accent: \"#FB923C\", varBg: \"rgba(251,146,60,0.14)\", fillBg: \"rgba(74,222,128,0.14)\", fill: \"#4ADE80\", ring: \"rgba(245,244,241,0.6)\", scrim: \"rgba(0,0,0,0.6)\", input: \"#0D0D0D\" },\n  light: { bg: \"#FAFAF8\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", faint: \"rgba(10,10,10,0.42)\", card: \"#FFFFFF\", raised: \"#FFFFFF\", border: \"rgba(10,10,10,0.09)\", hover: \"rgba(10,10,10,0.03)\", chip: \"rgba(10,10,10,0.05)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", accent: \"#EA580C\", varBg: \"rgba(234,88,12,0.1)\", fillBg: \"rgba(21,128,61,0.1)\", fill: \"#15803D\", ring: \"rgba(10,10,10,0.5)\", scrim: \"rgba(10,10,10,0.35)\", input: \"#FAFAF8\" },\n};\nconst CAT_COLORS = [\"#FB923C\", \"#60A5FA\", \"#A78BFA\", \"#4ADE80\", \"#F472B6\", \"#FBBF24\", \"#2DD4BF\"];\n\nconst DEFAULT_PROMPTS: PromptItem[] = [\n  { id: \"p1\", title: \"Rewrite in a clearer tone\", category: \"Writing\", description: \"Make any draft easier to read.\", body: \"Rewrite the text below so it is clear and friendly for {{audience}}. Keep it under {{length}} words and keep every fact.\\n\\n{{text}}\", uses: 2841, author: \"Mara Okafor\", created: 3 },\n  { id: \"p2\", title: \"Explain this code\", category: \"Coding\", description: \"Step-by-step walkthrough with bug spotting.\", body: \"Explain what this {{language}} code does, step by step, for a {{level}} developer. Point out any bugs or risky lines.\\n\\n{{code}}\", uses: 3920, author: \"Daniel Reyes\", created: 6 },\n  { id: \"p3\", title: \"Write unit tests\", category: \"Coding\", description: \"Edge cases included, named by behaviour.\", body: \"Write {{framework}} tests for the function below. Cover edge cases and name each test after the behaviour it checks.\\n\\n{{code}}\", uses: 1488, author: \"Daniel Reyes\", created: 9 },\n  { id: \"p4\", title: \"Launch email\", category: \"Marketing\", description: \"Subject, three paragraphs, one call to action.\", body: \"Write a launch email for {{product}} aimed at {{audience}}. One subject line, three short paragraphs and a single call to action: {{call_to_action}}.\", uses: 1203, author: \"Lena Brandt\", created: 8 },\n  { id: \"p5\", title: \"Hero headlines\", category: \"Marketing\", description: \"Five headline and subheadline pairs.\", body: \"Give me 5 hero headlines with subheadlines for {{product}}, which helps {{audience}} {{benefit}}. Avoid buzzwords.\", uses: 2210, author: \"Lena Brandt\", created: 4 },\n  { id: \"p6\", title: \"Summarise a paper\", category: \"Research\", description: \"Question, method, result, limits, why it matters.\", body: \"Summarise the paper below in 5 bullets for {{audience}}: the question, the method, the result, the limits and why it matters.\\n\\n{{text}}\", uses: 960, author: \"Tomás Ferreira\", created: 2 },\n  { id: \"p7\", title: \"Compare two options\", category: \"Research\", description: \"Table with cost, effort, risk and a pick.\", body: \"Compare {{option_a}} and {{option_b}} for {{use_case}}. Use a table with cost, effort and risk, then give a clear recommendation.\", uses: 1735, author: \"Tomás Ferreira\", created: 7 },\n  { id: \"p8\", title: \"Calm reply to an upset customer\", category: \"Support\", description: \"Acknowledge, explain, make it right.\", body: \"Draft a calm reply to this customer. Acknowledge the problem, explain {{fix}} and offer {{compensation}}. Sign as {{name}}.\\n\\n{{message}}\", uses: 2560, author: \"Mara Okafor\", created: 5 },\n  { id: \"p9\", title: \"Meeting notes to actions\", category: \"Writing\", description: \"Owners and due dates, gaps flagged.\", body: \"Turn these meeting notes into action items with an owner and a due date. Flag anything that has no owner.\\n\\n{{notes}}\", uses: 1890, author: \"Lena Brandt\", created: 1 },\n  { id: \"p10\", title: \"FAQ from support tickets\", category: \"Support\", description: \"The five questions customers ask most.\", body: \"Read these support tickets and write the 5 questions customers ask most, each with a short answer in plain words.\\n\\n{{tickets}}\", uses: 720, author: \"Mara Okafor\", created: 10 },\n];\nconst LONG_VARS = new Set([\"text\", \"code\", \"notes\", \"message\", \"tickets\", \"content\", \"input\"]);\nconst varsOf = (body: string) => Array.from(new Set(Array.from(body.matchAll(/\\{\\{\\s*([\\w-]+)\\s*\\}\\}/g), (m) => m[1])));\nconst label = (v: string) => v.replace(/[_-]/g, \" \").replace(/^\\w/, (c) => c.toUpperCase());\nconst fill = (body: string, values: Record<string, string>) => body.replace(/\\{\\{\\s*([\\w-]+)\\s*\\}\\}/g, (m, v: string) => values[v]?.trim() || m);\nconst compact = (n: number) => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : String(n));\n\ntype Sort = \"popular\" | \"recent\" | \"favorites\";\n\nexport function PromptLibrary({ title = \"Prompt library\", prompts, categories, onUse, onCreate, theme = \"dark\", className }: PromptLibraryProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [list, setList] = React.useState<PromptItem[]>(() => prompts ?? DEFAULT_PROMPTS);\n  const cats = categories ?? Array.from(new Set(list.map((x) => x.category)));\n  const [cat, setCat] = React.useState(\"All\");\n  const [q, setQ] = React.useState(\"\");\n  const [sort, setSort] = React.useState<Sort>(\"popular\");\n  const [fav, setFav] = React.useState<string[]>([\"p2\", \"p8\"]);\n  const [openId, setOpenId] = React.useState<string | null>(null);\n  const [creating, setCreating] = React.useState(false);\n  const [values, setValues] = React.useState<Record<string, string>>({});\n  const [toast, setToast] = React.useState<string | null>(null);\n  const [fresh, setFresh] = React.useState<string | null>(null);\n  const [draft, setDraft] = React.useState({ title: \"\", category: \"\", body: \"\" });\n  const returnTo = React.useRef<HTMLElement | null>(null);\n  const seq = React.useRef(0);\n  const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n  React.useEffect(\n    () => () => {\n      if (timer.current) clearTimeout(timer.current);\n    },\n    [],\n  );\n\n  const color = (c: string) => CAT_COLORS[Math.max(0, cats.indexOf(c)) % CAT_COLORS.length];\n  const query = q.trim().toLowerCase();\n  const rows = list\n    .filter((x) => (cat === \"All\" || x.category === cat) && (sort !== \"favorites\" || fav.includes(x.id)) && (!query || `${x.title} ${x.description ?? \"\"} ${x.body}`.toLowerCase().includes(query)))\n    .sort((a, b) => (sort === \"recent\" ? (b.created ?? 0) - (a.created ?? 0) : (b.uses ?? 0) - (a.uses ?? 0)));\n  const current = list.find((x) => x.id === openId) ?? null;\n  const vars = current ? varsOf(current.body) : [];\n  const filled = current ? fill(current.body, values) : \"\";\n  const dialogOpen = !!current || creating;\n\n  const say = (t: string) => {\n    setToast(t);\n    if (timer.current) clearTimeout(timer.current);\n    timer.current = setTimeout(() => setToast(null), 2200);\n  };\n  const close = () => {\n    setOpenId(null);\n    setCreating(false);\n    const el = returnTo.current;\n    if (el) requestAnimationFrame(() => el.focus());\n  };\n  const openPrompt = (id: string, el: HTMLElement) => {\n    returnTo.current = el;\n    setValues({});\n    setOpenId(id);\n  };\n  const toggleFav = (id: string) => setFav((v) => (v.includes(id) ? v.filter((x) => x !== id) : [...v, id]));\n  const focusFirst = React.useCallback((el: HTMLElement | null) => el?.focus({ preventScroll: true }), []);\n  const save = () => {\n    if (!draft.title.trim() || !draft.body.trim()) return;\n    seq.current += 1;\n    const item: PromptItem = { id: `new-${seq.current}`, title: draft.title.trim(), category: draft.category || cats[0] || \"General\", body: draft.body.trim(), description: \"Your prompt\", uses: 0, author: \"You\", created: Math.max(0, ...list.map((x) => x.created ?? 0)) + 1 };\n    setList((v) => [item, ...v]);\n    setFresh(item.id);\n    setSort(\"recent\");\n    setCat(\"All\");\n    setDraft({ title: \"\", category: \"\", body: \"\" });\n    setCreating(false);\n    onCreate?.(item);\n    say(\"Prompt saved\");\n    const el = returnTo.current;\n    if (el) requestAnimationFrame(() => el.focus());\n  };\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.card } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const field = cn(\"w-full rounded-lg border px-3 py-2 text-[13.5px]\", focus);\n  const fieldStyle = { borderColor: p.border, background: p.input, color: p.text, ...ring } as React.CSSProperties;\n  const renderBody = (body: string, vals?: Record<string, string>, clamp?: boolean) => (\n    <span className={cn(\"whitespace-pre-wrap\", clamp && \"line-clamp-3\")}>\n      {body.split(/(\\{\\{\\s*[\\w-]+\\s*\\}\\})/g).map((part, i) => {\n        const m = part.match(/^\\{\\{\\s*([\\w-]+)\\s*\\}\\}$/);\n        if (!m) return <React.Fragment key={i}>{part}</React.Fragment>;\n        const v = vals?.[m[1]]?.trim();\n        return v ? (\n          <mark key={i} className=\"rounded px-1\" style={{ background: p.fillBg, color: p.fill }}>\n            {v}\n          </mark>\n        ) : (\n          <span key={i} className=\"rounded px-1 font-medium\" style={{ background: p.varBg, color: p.accent }}>\n            {label(m[1])}\n          </span>\n        );\n      })}\n    </span>\n  );\n  const star = (id: string, name: string) => (\n    <button type=\"button\" onClick={() => toggleFav(id)} aria-pressed={fav.includes(id)} aria-label={`Favorite ${name}`} className={cn(\"relative z-10 flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-lg border-0 bg-transparent\", focus)} style={{ color: fav.includes(id) ? p.accent : p.faint, ...ring }}>\n      <motion.svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill={fav.includes(id) ? \"currentColor\" : \"none\"} stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinejoin=\"round\" aria-hidden=\"true\" animate={fav.includes(id) && !reduce ? { scale: [1, 1.3, 1] } : { scale: 1 }} transition={{ duration: 0.3 }}>\n        <path d=\"m12 3 2.8 5.7 6.2.9-4.5 4.4 1 6.2L12 17.3 6.5 20.2l1-6.2L3 9.6l6.2-.9L12 3Z\" />\n      </motion.svg>\n    </button>\n  );\n  const draftVars = varsOf(draft.body);\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"relative mx-auto max-w-6xl px-4 py-10 @[640px]:px-6 @[640px]:py-14\">\n        {/* Header */}\n        <div className=\"flex flex-wrap items-end justify-between gap-4\">\n          <div>\n            <h2 className=\"m-0 text-[26px] font-semibold tracking-[-0.02em]\">{title}</h2>\n            <p className=\"m-0 mt-1 text-[14px]\" style={{ color: p.muted }}>\n              Reusable prompts with fill-in fields. {list.length} prompts.\n            </p>\n          </div>\n          <div className=\"flex w-full gap-2 @[640px]:w-auto\">\n            <label className=\"relative min-w-0 flex-1 @[640px]:w-64 @[640px]:flex-none\">\n              <span className=\"sr-only\">Search prompts</span>\n              <svg className=\"pointer-events-none absolute top-1/2 left-3 -translate-y-1/2\" width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\" style={{ color: p.faint }}>\n                <circle cx=\"11\" cy=\"11\" r=\"7\" />\n                <path d=\"m20 20-3.5-3.5\" />\n              </svg>\n              <input type=\"search\" value={q} onChange={(e) => setQ(e.target.value)} placeholder=\"Search prompts\" className={cn(\"h-10 w-full rounded-xl border pr-3 pl-9 text-[14px]\", focus)} style={{ borderColor: p.border, background: p.card, color: p.text, ...ring }} />\n            </label>\n            <button\n              type=\"button\"\n              onClick={(e) => {\n                returnTo.current = e.currentTarget;\n                setCreating(true);\n              }}\n              className={cn(\"flex h-10 shrink-0 cursor-pointer items-center gap-1.5 rounded-xl border-0 px-4 text-[14px] font-medium\", focus)}\n              style={{ background: p.on, color: p.onText, ...ring }}\n            >\n              <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                <path d=\"M12 5v14M5 12h14\" />\n              </svg>\n              New prompt\n            </button>\n          </div>\n        </div>\n\n        <div className=\"mt-6 grid gap-6 @[800px]:grid-cols-[180px_1fr]\">\n          {/* Categories */}\n          <nav aria-label=\"Categories\" className=\"-mx-4 overflow-x-auto px-4 @[800px]:mx-0 @[800px]:overflow-visible @[800px]:px-0\">\n            <ul className=\"m-0 flex list-none gap-1 p-0 @[800px]:flex-col\">\n              {[\"All\", ...cats].map((c) => {\n                const on = cat === c;\n                const n = c === \"All\" ? list.length : list.filter((x) => x.category === c).length;\n                return (\n                  <li key={c} className=\"shrink-0\">\n                    <button type=\"button\" aria-current={on ? \"true\" : undefined} onClick={() => setCat(c)} className={cn(\"relative flex w-full cursor-pointer items-center justify-between gap-3 rounded-lg border-0 bg-transparent px-3 py-2 text-left text-[13.5px]\", focus)} style={{ color: on ? p.text : p.muted, ...ring }}>\n                      {on && <motion.span layoutId={`${uid}-cat`} className=\"absolute inset-0 rounded-lg\" style={{ background: p.chip }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 38 }} />}\n                      <span className=\"relative flex items-center gap-2\">\n                        {c !== \"All\" && <span className=\"h-2 w-2 rounded-full\" style={{ background: color(c) }} aria-hidden=\"true\" />}\n                        {c}\n                      </span>\n                      <span className=\"relative text-[12px] tabular-nums\" style={{ color: p.faint }}>\n                        {n}\n                      </span>\n                    </button>\n                  </li>\n                );\n              })}\n            </ul>\n          </nav>\n\n          <div className=\"min-w-0\">\n            <div role=\"radiogroup\" aria-label=\"Sort\" className=\"mb-4 flex w-fit rounded-lg border p-0.5\" style={{ borderColor: p.border }}>\n              {([\"popular\", \"recent\", \"favorites\"] as Sort[]).map((s) => (\n                <button key={s} type=\"button\" role=\"radio\" aria-checked={sort === s} onClick={() => setSort(s)} className={cn(\"relative h-7 cursor-pointer rounded-md border-0 bg-transparent px-3 text-[12.5px] capitalize\", focus)} style={{ color: sort === s ? p.text : p.faint, ...ring }}>\n                  {sort === s && <motion.span layoutId={`${uid}-sort`} className=\"absolute inset-0 rounded-md\" style={{ background: p.chip }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 38 }} />}\n                  <span className=\"relative\">\n                    {s}\n                    {s === \"favorites\" ? ` ${fav.length}` : \"\"}\n                  </span>\n                </button>\n              ))}\n            </div>\n\n            <ul className=\"m-0 grid list-none gap-3 p-0 @[560px]:grid-cols-2 @[1000px]:grid-cols-3\">\n              <AnimatePresence initial={false} mode=\"popLayout\">\n                {rows.map((x) => (\n                  <motion.li key={x.id} layout={!reduce} initial={reduce ? false : { opacity: 0, scale: 0.97 }} animate={{ opacity: 1, scale: 1 }} exit={reduce ? undefined : { opacity: 0, scale: 0.97, transition: { duration: 0.12 } }} transition={{ duration: 0.2 }} className=\"group relative flex flex-col rounded-2xl border p-4 transition-colors hover:bg-[var(--pl-hover)]\" style={{ background: p.card, borderColor: fresh === x.id ? p.accent : p.border, [\"--pl-hover\" as string]: p.hover }}>\n                    <div className=\"flex items-start justify-between gap-2\">\n                      <span className=\"flex items-center gap-1.5 rounded-full px-2 py-0.5 text-[11.5px] font-medium\" style={{ background: p.chip, color: color(x.category) }}>\n                        <span className=\"h-1.5 w-1.5 rounded-full\" style={{ background: color(x.category) }} aria-hidden=\"true\" />\n                        {x.category}\n                      </span>\n                      <span className=\"-mt-1.5 -mr-1.5\">{star(x.id, x.title)}</span>\n                    </div>\n                    <h3 className=\"m-0 mt-2 text-[15px] font-semibold tracking-[-0.01em]\">\n                      <button type=\"button\" onClick={(e) => openPrompt(x.id, e.currentTarget)} className={cn(\"cursor-pointer rounded border-0 bg-transparent p-0 text-left after:absolute after:inset-0 after:rounded-2xl after:content-['']\", focus)} style={{ color: p.text, ...ring }}>\n                        {x.title}\n                      </button>\n                    </h3>\n                    {x.description && (\n                      <p className=\"m-0 mt-1 text-[13px]\" style={{ color: p.muted }}>\n                        {x.description}\n                      </p>\n                    )}\n                    <p className=\"m-0 mt-3 flex-1 text-[12.5px] leading-[1.65]\" style={{ color: p.faint }}>\n                      {renderBody(x.body, undefined, true)}\n                    </p>\n                    <div className=\"mt-4 flex items-center justify-between text-[12px]\" style={{ color: p.faint }}>\n                      <span className=\"flex items-center gap-2\">\n                        <span className=\"flex h-5 w-5 items-center justify-center rounded-full text-[9px] font-semibold\" style={{ background: p.chip, color: p.muted }} aria-hidden=\"true\">\n                          {(x.author ?? \"?\")\n                            .split(\" \")\n                            .map((w) => w[0])\n                            .join(\"\")\n                            .slice(0, 2)}\n                        </span>\n                        {x.author}\n                      </span>\n                      <span className=\"tabular-nums\">{fresh === x.id ? \"New\" : `${compact(x.uses ?? 0)} uses`}</span>\n                    </div>\n                  </motion.li>\n                ))}\n              </AnimatePresence>\n            </ul>\n            {rows.length === 0 && (\n              <div className=\"rounded-2xl border border-dashed px-6 py-14 text-center text-[14px]\" style={{ borderColor: p.border, color: p.muted }}>\n                {sort === \"favorites\" ? \"No favorites here yet. Star a prompt to keep it close.\" : \"No prompts match your search.\"}\n              </div>\n            )}\n          </div>\n        </div>\n\n        {/* Detail / create panel */}\n        <AnimatePresence>\n          {dialogOpen && (\n            <motion.div className=\"absolute inset-0 z-30 flex justify-end\" initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={{ duration: 0.18 }}>\n              <button type=\"button\" tabIndex={-1} aria-label=\"Close\" className=\"absolute inset-0 cursor-default border-0\" style={{ background: p.scrim }} onClick={close} />\n              <motion.div\n                role=\"dialog\"\n                aria-modal=\"true\"\n                aria-labelledby={`${uid}-dlg`}\n                onKeyDown={(e) => {\n                  if (e.key === \"Escape\") {\n                    e.stopPropagation();\n                    close();\n                  }\n                }}\n                initial={reduce ? false : { x: 40, opacity: 0 }}\n                animate={{ x: 0, opacity: 1 }}\n                exit={reduce ? undefined : { x: 40, opacity: 0 }}\n                transition={{ type: \"spring\", stiffness: 420, damping: 38 }}\n                className=\"sticky top-0 flex max-h-[100dvh] min-h-[min(100%,100dvh)] w-full max-w-[480px] flex-col self-start overflow-y-auto border-l\"\n                style={{ background: p.raised, borderColor: p.border }}\n              >\n                <div className=\"flex items-start justify-between gap-3 border-b p-5\" style={{ borderColor: p.border }}>\n                  <div className=\"min-w-0\">\n                    {current && (\n                      <span className=\"text-[12px] font-medium\" style={{ color: color(current.category) }}>\n                        {current.category}\n                      </span>\n                    )}\n                    <h3 id={`${uid}-dlg`} className=\"m-0 mt-0.5 text-[18px] font-semibold tracking-[-0.01em]\">\n                      {current ? current.title : \"New prompt\"}\n                    </h3>\n                  </div>\n                  <div className=\"flex items-center gap-1\">\n                    {current && star(current.id, current.title)}\n                    <button type=\"button\" onClick={close} aria-label=\"Close\" className={cn(\"flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg border-0 bg-transparent\", focus)} style={{ color: p.muted, ...ring }}>\n                      <svg width=\"14\" height=\"14\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                        <path d=\"m4 4 8 8M12 4l-8 8\" />\n                      </svg>\n                    </button>\n                  </div>\n                </div>\n\n                {current ? (\n                  <div className=\"flex flex-1 flex-col gap-5 p-5\">\n                    {vars.length > 0 && (\n                      <fieldset className=\"m-0 flex flex-col gap-3 border-0 p-0\">\n                        <legend className=\"mb-2 p-0 text-[12.5px]\" style={{ color: p.faint }}>\n                          Fill in {vars.length} {vars.length === 1 ? \"field\" : \"fields\"}\n                        </legend>\n                        {vars.map((v, i) => (\n                          <label key={v} className=\"flex flex-col gap-1.5 text-[12.5px]\" style={{ color: p.muted }}>\n                            {label(v)}\n                            {LONG_VARS.has(v) ? (\n                              <textarea ref={i === 0 ? focusFirst : undefined} rows={3} value={values[v] ?? \"\"} onChange={(e) => setValues((s) => ({ ...s, [v]: e.target.value }))} className={cn(field, \"resize-y font-mono text-[12.5px]\")} style={fieldStyle} />\n                            ) : (\n                              <input ref={i === 0 ? focusFirst : undefined} value={values[v] ?? \"\"} onChange={(e) => setValues((s) => ({ ...s, [v]: e.target.value }))} className={field} style={fieldStyle} />\n                            )}\n                          </label>\n                        ))}\n                      </fieldset>\n                    )}\n                    <div>\n                      <p className=\"m-0 mb-1.5 flex items-center justify-between text-[12.5px]\" style={{ color: p.faint }}>\n                        Preview\n                        <span className=\"tabular-nums\">\n                          {vars.filter((v) => values[v]?.trim()).length}/{vars.length} filled\n                        </span>\n                      </p>\n                      <div className=\"rounded-xl border p-3.5 text-[13.5px] leading-[1.7]\" style={{ borderColor: p.border, background: p.input }} aria-live=\"polite\">\n                        {renderBody(current.body, values)}\n                      </div>\n                    </div>\n                    <div className=\"sticky bottom-0 -mx-5 mt-auto -mb-5 flex gap-2 border-t px-5 py-4\" style={{ background: p.raised, borderColor: p.border }}>\n                      <button\n                        type=\"button\"\n                        onClick={() => {\n                          navigator.clipboard?.writeText(filled).catch(() => {});\n                          say(\"Copied to clipboard\");\n                        }}\n                        className={cn(\"flex h-10 flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-xl border text-[14px]\", focus)}\n                        style={{ borderColor: p.border, background: \"transparent\", color: p.text, ...ring }}\n                      >\n                        <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                          <path d=\"M9 9h10v10H9zM5 15V5h10\" />\n                        </svg>\n                        Copy\n                      </button>\n                      <button\n                        type=\"button\"\n                        onClick={() => {\n                          onUse?.(filled, current);\n                          setList((l) => l.map((x) => (x.id === current.id ? { ...x, uses: (x.uses ?? 0) + 1 } : x)));\n                          close();\n                          say(\"Prompt sent to chat\");\n                        }}\n                        className={cn(\"flex h-10 flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-xl border-0 text-[14px] font-medium\", focus)}\n                        style={{ background: p.on, color: p.onText, ...ring }}\n                      >\n                        Use in chat\n                        <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                          <path d=\"M5 12h14m-6-6 6 6-6 6\" />\n                        </svg>\n                      </button>\n                    </div>\n                  </div>\n                ) : (\n                  <form\n                    className=\"flex flex-1 flex-col gap-4 p-5\"\n                    onSubmit={(e) => {\n                      e.preventDefault();\n                      save();\n                    }}\n                  >\n                    <label className=\"flex flex-col gap-1.5 text-[12.5px]\" style={{ color: p.muted }}>\n                      Title\n                      <input ref={focusFirst} required value={draft.title} onChange={(e) => setDraft((d) => ({ ...d, title: e.target.value }))} placeholder=\"e.g. Turn bullet points into a blog intro\" className={field} style={fieldStyle} />\n                    </label>\n                    <label className=\"flex flex-col gap-1.5 text-[12.5px]\" style={{ color: p.muted }}>\n                      Category\n                      <select value={draft.category || cats[0]} onChange={(e) => setDraft((d) => ({ ...d, category: e.target.value }))} className={cn(field, \"cursor-pointer\")} style={fieldStyle}>\n                        {cats.map((c) => (\n                          <option key={c}>{c}</option>\n                        ))}\n                      </select>\n                    </label>\n                    <label className=\"flex flex-col gap-1.5 text-[12.5px]\" style={{ color: p.muted }}>\n                      Prompt\n                      <textarea required rows={6} value={draft.body} onChange={(e) => setDraft((d) => ({ ...d, body: e.target.value }))} placeholder=\"Write the prompt. Use {{name}} for anything people should fill in.\" className={cn(field, \"resize-y leading-[1.6]\")} style={fieldStyle} aria-describedby={`${uid}-vars`} />\n                    </label>\n                    <div id={`${uid}-vars`} className=\"flex min-h-6 flex-wrap items-center gap-1.5 text-[12px]\" style={{ color: p.faint }} aria-live=\"polite\">\n                      {draftVars.length ? (\n                        <>\n                          Fields found:\n                          {draftVars.map((v) => (\n                            <span key={v} className=\"rounded px-1.5 py-0.5 font-medium\" style={{ background: p.varBg, color: p.accent }}>\n                              {label(v)}\n                            </span>\n                          ))}\n                        </>\n                      ) : (\n                        <>\n                          Tip: wrap words in double braces, like <code className=\"font-mono\">{\"{{topic}}\"}</code>, to make a field.\n                        </>\n                      )}\n                    </div>\n                    <div className=\"sticky bottom-0 -mx-5 mt-auto -mb-5 flex gap-2 border-t px-5 py-4\" style={{ background: p.raised, borderColor: p.border }}>\n                      <button type=\"button\" onClick={close} className={cn(\"h-10 flex-1 cursor-pointer rounded-xl border text-[14px]\", focus)} style={{ borderColor: p.border, background: \"transparent\", color: p.text, ...ring }}>\n                        Cancel\n                      </button>\n                      <button type=\"submit\" disabled={!draft.title.trim() || !draft.body.trim()} className={cn(\"h-10 flex-1 cursor-pointer rounded-xl border-0 text-[14px] font-medium disabled:cursor-not-allowed disabled:opacity-40\", focus)} style={{ background: p.on, color: p.onText, ...ring }}>\n                        Save prompt\n                      </button>\n                    </div>\n                  </form>\n                )}\n              </motion.div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n\n        <div className=\"pointer-events-none absolute inset-x-0 bottom-4 z-40 flex justify-center px-4\" aria-live=\"polite\">\n          <AnimatePresence>\n            {toast && (\n              <motion.div key={toast} initial={reduce ? false : { opacity: 0, y: 10 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0, y: 6 }} className=\"flex items-center gap-2 rounded-full px-4 py-2 text-[13px] font-medium shadow-lg\" style={{ background: p.on, color: p.onText }}>\n                <svg width=\"13\" height=\"13\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                  <path d=\"m3 8.5 3 3 7-7\" />\n                </svg>\n                {toast}\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default PromptLibrary;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}