{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-mail-composer",
  "title": "AI Mail Composer",
  "description": "A Dynamic Island-inspired email composer with tone selection, async draft generation, editable subject and body, and send states.",
  "dependencies": [
    "motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/ai-mail-composer/ai-mail-composer.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\nimport { ArrowUpRight, Check, Mail, Sparkles, RotateCcw, X } from \"lucide-react\";\n\nexport type MailTone = \"Professional\" | \"Friendly\" | \"Concise\";\nexport interface MailDraft { to: string; subject: string; body: string }\nexport interface AIMailComposerProps {\n  defaultTo?: string;\n  defaultPrompt?: string;\n  onGenerate?: (prompt: string, tone: MailTone) => Omit<MailDraft, \"to\"> | Promise<Omit<MailDraft, \"to\">>;\n  onSend?: (draft: MailDraft) => void | Promise<void>;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst SHEEN = \"linear-gradient(115deg,rgba(255,255,255,.08),rgba(255,255,255,.02) 30%,transparent 48%,rgba(255,255,255,.04) 74%,transparent),linear-gradient(180deg,rgba(255,255,255,.05),transparent 60%)\";\nfunction Island({ children, theme, active = false, warm = false, className }: { children: React.ReactNode; theme: \"dark\" | \"light\"; active?: boolean; warm?: boolean; className?: string }) {\n  const reduce = useReducedMotion();\n  return <motion.div layout={!reduce} transition={{ type: \"spring\", stiffness: 260, damping: 30 }} className={twMerge(clsx(\"relative isolate w-full rounded-[32px] border font-sans antialiased [font-family:Inter,ui-sans-serif,system-ui,sans-serif]\", theme === \"dark\" ? \"border-white/[0.09] bg-[#0E0E10] text-[#EDEDED]\" : \"border-black/[0.09] bg-[#f7f7f8] text-[#202023]\", className))} style={{ backgroundImage: SHEEN, boxShadow: theme === \"dark\" ? \"inset 0 1px 0 #ffffff1f,0 16px 48px #00000025\" : \"inset 0 1px 0 #ffffff,0 16px 48px #00000008\" }}>\n    <motion.div aria-hidden=\"true\" className=\"pointer-events-none absolute -inset-px rounded-[inherit]\" animate={{ opacity: active && !reduce ? [0.35, 0.8, 0.35] : active ? 0.5 : 0.18 }} transition={{ duration: 3, repeat: active && !reduce ? Infinity : 0 }} style={{ padding: 1, background: warm ? \"conic-gradient(from 40deg,transparent 10%,#FF7BD5 32%,#FFB86B 45%,transparent 65%)\" : \"conic-gradient(from 40deg,transparent 10%,#7CF3FF 32%,#6EA8FF 45%,#9B7BFF 55%,transparent 75%)\", mask: \"linear-gradient(#fff 0 0) content-box,linear-gradient(#fff 0 0)\", maskComposite: \"exclude\", WebkitMaskComposite: \"xor\" }} />\n    {children}\n  </motion.div>;\n}\nfunction Orb({ active = false, warm = false, size = 40 }: { active?: boolean; warm?: boolean; size?: number }) {\n  const reduce = useReducedMotion();\n  return <span aria-hidden=\"true\" className=\"relative inline-flex shrink-0 items-center justify-center\" style={{ width: size, height: size }}>\n    <motion.span className=\"absolute inset-0 rounded-full blur-md\" style={{ background: warm ? \"radial-gradient(circle,#ffb86b55,transparent 70%)\" : \"radial-gradient(circle,#9b7bff55,transparent 70%)\" }} animate={{ opacity: active && !reduce ? [0.3, 0.9, 0.3] : 0.3 }} transition={{ duration: 2.5, repeat: active && !reduce ? Infinity : 0 }} />\n    <motion.svg viewBox=\"0 0 40 40\" className=\"relative size-full\" animate={active && !reduce ? { rotate: [0, 12, 0] } : { rotate: 0 }} transition={{ duration: 5, repeat: active && !reduce ? Infinity : 0 }}>{Array.from({ length: 81 }, (_, i) => { const x = i % 9 - 4; const y = Math.floor(i / 9) - 4; const d = Math.hypot(x, y); return d <= 4.1 ? <circle key={i} cx={20 + x * 3.9} cy={20 + y * 3.9} r={Number((1 - d * .13).toFixed(3))} fill=\"currentColor\" opacity={Number((.95 - d * .16).toFixed(3))} /> : null; })}</motion.svg>\n  </span>;\n}\nconst action = \"inline-flex min-h-10 shrink-0 items-center justify-center gap-2 rounded-full border border-current/[0.12] px-4 text-[11px] transition-colors hover:bg-current/[0.06] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#9B7BFF] disabled:cursor-not-allowed disabled:opacity-35 motion-reduce:transition-none [&_svg]:shrink-0\";\n\nexport function AIMailComposer({ defaultTo = \"alex@studio.co\", defaultPrompt = \"Follow up on our design review. Share that the new prototype is ready and ask for feedback by Friday.\", onGenerate, onSend, theme = \"dark\", className }: AIMailComposerProps) {\n  const [to, setTo] = React.useState(defaultTo);\n  const [prompt, setPrompt] = React.useState(defaultPrompt);\n  const [tone, setTone] = React.useState<MailTone>(\"Professional\");\n  const [draft, setDraft] = React.useState<Omit<MailDraft, \"to\"> | null>(null);\n  const [pending, setPending] = React.useState<\"generate\" | \"send\" | null>(null);\n  const [error, setError] = React.useState(\"\");\n  const [sent, setSent] = React.useState(false);\n  const generation = React.useRef(0);\n  const subjectRef = React.useRef<HTMLInputElement>(null);\n  const id = React.useId();\n  React.useEffect(() => () => { generation.current++; }, []);\n  async function generate() {\n    if (!prompt.trim() || pending) return;\n    const token = ++generation.current; setPending(\"generate\"); setError(\"\"); setSent(false);\n    try {\n      const result = onGenerate ? await onGenerate(prompt.trim(), tone) : { subject: \"Prototype ready for your feedback\", body: tone === \"Concise\" ? \"Hi Alex,\\n\\nThe updated prototype is ready after our design review. Could you share your feedback by Friday?\\n\\nThanks!\" : tone === \"Friendly\" ? \"Hey Alex,\\n\\nThanks for such a great design review! The updated prototype is ready for you to explore. I’d love to hear what you think by Friday.\\n\\nLooking forward to your thoughts!\" : \"Hi Alex,\\n\\nThank you for your time during our design review. The updated prototype is now ready, with the changes we discussed.\\n\\nCould you please share your feedback by Friday so we can prepare the next iteration?\\n\\nBest regards\" };\n      if (token === generation.current) { if (!result.subject?.trim() || !result.body?.trim()) throw new Error(\"The draft is incomplete. Please try again.\"); setDraft(result); }\n    } catch (e) { if (token === generation.current) setError(e instanceof Error ? e.message : \"Could not generate your draft.\"); }\n    finally { if (token === generation.current) setPending(null); }\n  }\n  const hasDraft = draft !== null;\n  React.useEffect(() => { if (hasDraft && !pending) subjectRef.current?.focus(); }, [hasDraft, pending]);\n  async function send(e: React.FormEvent<HTMLFormElement>) {\n    e.preventDefault(); if (!draft || pending) return;\n    const token = ++generation.current; setPending(\"send\"); setError(\"\");\n    try { await onSend?.({ to: to.trim(), subject: draft.subject.trim(), body: draft.body.trim() }); if (token === generation.current) setSent(true); }\n    catch (e) { if (token === generation.current) setError(e instanceof Error ? e.message : \"Could not send this email.\"); }\n    finally { if (token === generation.current) setPending(null); }\n  }\n  const field = \"w-full min-w-0 bg-transparent text-[13px] outline-none placeholder:opacity-35 focus-visible:ring-1 focus-visible:ring-[#9B7BFF]/60 rounded-md disabled:opacity-50\";\n  return <div className={twMerge(\"mx-auto w-full max-w-[540px]\", className)}><Island theme={theme} active={!!pending} warm={!!draft} className=\"overflow-hidden\">\n    <header className=\"flex items-center gap-3 px-6 pb-5 pt-6\"><Orb size={44} active={!!pending} warm={!!draft} /><div className=\"flex-1\"><h3 className=\"text-[15px] font-medium tracking-[-0.025em]\">A little help finding the words.</h3><p className=\"mt-1 text-[11px] opacity-40\">{pending === \"generate\" ? \"Turning your thoughts into a draft…\" : draft ? \"Make it yours before you send.\" : \"A thought in. A thoughtful email out.\"}</p></div><Mail size={20} className=\"hidden shrink-0 opacity-40 sm:block\" /></header>\n    {sent ? <div className=\"px-6 pb-6\"><div className=\"rounded-2xl border border-current/10 bg-current/[0.025] px-5 py-8 text-center\"><span className=\"mx-auto flex size-10 items-center justify-center rounded-full border border-current/10\"><Check size={22} /></span><p role=\"status\" className=\"mt-4 text-sm\">{onSend ? \"On its way.\" : \"Draft saved for this demo.\"}</p><p className=\"mt-2 break-all text-[11px] opacity-40\">{to}</p><button type=\"button\" onClick={() => { setSent(false); setDraft(null); }} className={action + \" mt-6\"}>Write another<ArrowUpRight size={16} /></button></div></div> : <form onSubmit={send} className=\"px-6 pb-6\">\n      <div className=\"flex items-center gap-3 border-y border-current/[0.08] py-3\"><label htmlFor={id + \"-to\"} className=\"w-9 shrink-0 text-[11px] opacity-40\">To</label><input id={id + \"-to\"} type=\"email\" required disabled={!!pending} value={to} onChange={e => setTo(e.target.value)} className={field} placeholder=\"name@company.com\" /></div>\n      {!draft ? <><label htmlFor={id + \"-prompt\"} className=\"mb-3 mt-5 block text-[11px] opacity-45\">What would you like to say?</label><textarea id={id + \"-prompt\"} value={prompt} disabled={!!pending} onChange={e => setPrompt(e.target.value)} className={field + \" min-h-28 resize-y rounded-2xl border border-current/10 bg-current/[0.025] p-4 leading-6\"} /><div role=\"group\" aria-label=\"Email tone\" className=\"mt-4 flex flex-wrap gap-1.5\">{([\"Professional\", \"Friendly\", \"Concise\"] as MailTone[]).map(t => <button key={t} type=\"button\" disabled={!!pending} aria-pressed={tone === t} onClick={() => setTone(t)} className={action + (tone === t ? \" bg-current/[0.08]\" : \" opacity-40\")}>{t}</button>)}</div></> : <><div className=\"flex items-center gap-3 border-b border-current/[0.08] py-3\"><label htmlFor={id + \"-subject\"} className=\"w-9 shrink-0 text-[11px] opacity-40\">Subject</label><input ref={subjectRef} id={id + \"-subject\"} required value={draft.subject} disabled={!!pending} onChange={e => setDraft({ ...draft, subject: e.target.value })} className={field} /></div><label htmlFor={id + \"-body\"} className=\"sr-only\">Email body</label><textarea id={id + \"-body\"} required disabled={!!pending} value={draft.body} onChange={e => setDraft({ ...draft, body: e.target.value })} className={field + \" mt-4 min-h-56 resize-y leading-7\"} /><div className=\"mt-2 flex gap-2\"><button type=\"button\" onClick={e => { e.preventDefault(); void generate(); }} disabled={!!pending} className={action}><RotateCcw size={16} />Regenerate</button><button type=\"button\" onClick={() => setDraft(null)} disabled={!!pending} className={action}><X size={16} />Back</button></div></>}\n      {error && <p role=\"alert\" className=\"mt-4 text-[11px] text-red-400\">{error}</p>}\n      <footer className=\"mt-5 flex flex-wrap items-center justify-between gap-3 border-t border-current/[0.08] pt-4\"><span className=\"max-w-[210px] text-[10px] leading-4 opacity-35\">{!onGenerate && !draft ? \"Demo · sample email based on the example brief\" : !onSend && draft ? \"Demo · no email will be sent\" : \"You’re always in control of the final words.\"}</span>{draft ? <button type=\"submit\" disabled={!!pending || !draft.subject.trim() || !draft.body.trim()} className={action + (theme === \"dark\" ? \" bg-[#EDEDED] text-[#0E0E10] hover:bg-white\" : \" bg-[#202023] text-white hover:bg-[#333]\")}>{pending === \"send\" ? \"Sending…\" : onSend ? \"Send email\" : \"Save draft\"}<ArrowUpRight size={17} /></button> : <button type=\"button\" disabled={!!pending || !prompt.trim()} onClick={e => { e.preventDefault(); void generate(); }} className={action + (theme === \"dark\" ? \" bg-[#EDEDED] text-[#0E0E10] hover:bg-white\" : \" bg-[#202023] text-white hover:bg-[#333]\")}><Sparkles size={17} />{pending === \"generate\" ? \"Drafting…\" : \"Draft with AI\"}</button>}</footer>\n    </form>}\n  </Island></div>;\n}\nexport default AIMailComposer;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}