{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "waitlist-form",
  "title": "Waitlist Form",
  "type": "registry:component",
  "description": "Email capture with avatar stack social proof, live join count and success state",
  "dependencies": [
    "motion@^12.43.0"
  ],
  "files": [
    {
      "path": "src/kavyn/waitlist-form.jsx",
      "type": "registry:file",
      "target": "@components/kavyn/waitlist-form.jsx",
      "content": "'use client'\n\nimport { useCallback, useEffect, useState } from 'react'\nimport { motion, AnimatePresence } from 'motion/react'\n\n// Default people are initials only, so the component makes no network requests out of the box.\n// Pass `people` with your own `src` photos (https, a path on your site, or a data:image URL).\nconst POOL = [\n  { id: 'p1', initials: 'AK', hue: '#d8b27a' },\n  { id: 'p2', initials: 'MS', hue: '#8fb996' },\n  { id: 'p3', initials: 'RJ', hue: '#e8a2b4' },\n  { id: 'p4', initials: 'PN', hue: '#b9b4ab' },\n  { id: 'p5', initials: 'DV', hue: '#c9a2e0' },\n  { id: 'p6', initials: 'SL', hue: '#e0a184' },\n  { id: 'p7', initials: 'TK', hue: '#c8a27a' },\n  { id: 'p8', initials: 'IB', hue: '#b5c48a' },\n  { id: 'p9', initials: 'AR', hue: '#d69bb8' },\n  { id: 'p10', initials: 'NK', hue: '#93b8a4' },\n  { id: 'p11', initials: 'SP', hue: '#c8a883' },\n  { id: 'p12', initials: 'RM', hue: '#a1a1a6' },\n]\n\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n\n// Only same-site paths, https and inline images are used as photos. Anything else (javascript:, http:, other schemes) falls back to initials.\nconst safeSrc = (src) => (typeof src === 'string' && /^(https:\\/\\/|\\/(?!\\/)|\\.{1,2}\\/|data:image\\/(png|jpe?g|gif|webp|avif);)/i.test(src.trim()) ? src.trim() : '')\n\nfunction Avatar({ person, first }) {\n  const src = safeSrc(person.src)\n  const [ok, setOk] = useState(true)\n  const [loaded, setLoaded] = useState(false)\n  return (\n    <motion.div\n      layout\n      initial={{ opacity: 0, scale: 0.4, x: -16 }}\n      animate={{ opacity: 1, scale: 1, x: 0 }}\n      transition={{ type: 'spring', stiffness: 160, damping: 22 }}\n      whileHover={{ scale: 1.12, transition: { type: 'spring', stiffness: 400, damping: 22 } }}\n      className=\"relative grid size-9 shrink-0 place-items-center overflow-hidden rounded-full border-2 border-bg text-[11px] font-semibold text-white\"\n      style={{ background: person.hue || '#8a8a93', marginLeft: first ? 0 : -8 }}\n    >\n      {person.initials}\n      {src && ok && (\n        <img\n          src={src}\n          referrerPolicy=\"no-referrer\"\n          alt=\"\"\n          loading=\"lazy\"\n          onLoad={() => setLoaded(true)}\n          onError={() => setOk(false)}\n          className=\"absolute inset-0 size-full rounded-full object-cover transition-opacity duration-300\"\n          style={{ opacity: loaded ? 1 : 0 }}\n        />\n      )}\n    </motion.div>\n  )\n}\n\n/** @param {{ placeholder?: any, buttonLabel?: any, successLabel?: any, retryLabel?: any, errorLabel?: any, count?: any, countLabel?: any, people?: any, visible?: any, autoJoin?: any, autoJoinInterval?: any, onSubmit?: any }} props */\nexport default function WaitlistForm({\n  placeholder = 'Enter your email',\n  buttonLabel = 'Join Waitlist',\n  successLabel = \"You're in!\",\n  retryLabel = 'Try again',\n  errorLabel = 'Could not join right now. Please try again.',\n  count = 32,\n  countLabel = 'People joined today',\n  people = POOL,\n  visible = 5,\n  autoJoin = false,\n  autoJoinInterval = 4800,\n  onSubmit = undefined,\n}) {\n  const [email, setEmail] = useState('')\n  const [state, setState] = useState('idle') // idle | sending | done | failed\n  const [shake, setShake] = useState(false)\n  const [joined, setJoined] = useState(0)\n  // Window start index into people; the visible stack is derived, so a face can never repeat.\n  const [start, setStart] = useState(0)\n  const done = state === 'done'\n  const n = people.length\n  const heads = n ? Array.from({ length: Math.min(visible, n) }, (_, i) => people[(start + i) % n]) : []\n\n  const pushOne = useCallback(() => {\n    setJoined((j) => j + 1)\n    if (n) setStart((s) => (s - 1 + n) % n)\n  }, [n])\n\n  // Demo-only conveyor: off by default so production counts stay real. Enable with autoJoin.\n  useEffect(() => {\n    if (!autoJoin || !n) return\n    const t = setInterval(pushOne, autoJoinInterval)\n    return () => clearInterval(t)\n  }, [autoJoin, autoJoinInterval, n, pushOne])\n\n  const submit = async (e) => {\n    e.preventDefault()\n    if (state === 'sending' || done) return\n    if (!EMAIL.test(email.trim())) {\n      setShake(true)\n      setTimeout(() => setShake(false), 450)\n      return\n    }\n    setState('sending')\n    try {\n      await onSubmit?.(email.trim())\n      setState('done')\n      pushOne()\n    } catch {\n      setState('failed')\n    }\n  }\n\n  return (\n    <div className=\"flex w-full max-w-md flex-col gap-4\">\n      <form onSubmit={submit} className=\"flex flex-col gap-3 sm:flex-row\">\n        <motion.input\n          type=\"email\"\n          value={email}\n          onChange={(e) => setEmail(e.target.value)}\n          placeholder={placeholder}\n          animate={shake || state === 'failed' ? { x: [0, -8, 8, -5, 5, 0] } : { x: 0 }}\n          transition={{ duration: 0.4 }}\n          className={`h-14 w-full flex-1 rounded-2xl border bg-panel2 px-5 text-sm text-tx outline-none transition-colors placeholder:text-faint ${shake || state === 'failed' ? 'border-red-400' : 'border-line focus:border-line2'}`}\n        />\n        <motion.button\n          type=\"submit\"\n          whileTap={{ scale: 0.97 }}\n          className=\"relative h-14 shrink-0 rounded-2xl bg-tx px-7 text-sm font-medium text-bg\"\n        >\n          <AnimatePresence mode=\"wait\" initial={false}>\n            <motion.span\n              key={state}\n              initial={{ y: 12, opacity: 0 }}\n              animate={{ y: 0, opacity: 1 }}\n              exit={{ y: -12, opacity: 0 }}\n              transition={{ duration: 0.18 }}\n              className=\"flex items-center justify-center gap-2\"\n            >\n              {done ? (\n                <>\n                  <svg viewBox=\"0 0 24 24\" className=\"size-4\">\n                    <motion.path d=\"M5 12l5 5 9-10\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.5\" strokeLinecap=\"round\" initial={{ pathLength: 0 }} animate={{ pathLength: 1 }} transition={{ duration: 0.35, delay: 0.05 }} />\n                  </svg>\n                  {successLabel}\n                </>\n              ) : state === 'sending' ? (\n                <motion.span animate={{ rotate: 360 }} transition={{ repeat: Infinity, ease: 'linear', duration: 0.8 }} className=\"size-4 rounded-full border-2 border-bg/30 border-t-bg\" />\n              ) : state === 'failed' ? (\n                retryLabel\n              ) : (\n                buttonLabel\n              )}\n            </motion.span>\n          </AnimatePresence>\n        </motion.button>\n      </form>\n      <AnimatePresence initial={false}>\n        {state === 'failed' && (\n          <motion.p initial={{ opacity: 0, y: -4 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0 }} className=\"-mt-1 text-xs text-red-400\">\n            {errorLabel}\n          </motion.p>\n        )}\n      </AnimatePresence>\n      <div className=\"flex items-center gap-4\">\n        {heads.length > 0 && (\n          <div className=\"flex\">\n            {heads.map((p, i) => <Avatar key={p.id ?? p.initials} person={p} first={i === 0} />)}\n          </div>\n        )}\n        <div className=\"flex items-center text-xs\">\n          <span className=\"relative z-10 rounded-full bg-tx px-2.5 py-1 font-semibold text-bg\">\n            <AnimatePresence mode=\"popLayout\" initial={false}>\n              <motion.span key={count + joined} initial={{ y: 10, opacity: 0 }} animate={{ y: 0, opacity: 1 }} exit={{ y: -10, opacity: 0 }} transition={{ type: 'spring', stiffness: 260, damping: 30 }} className=\"inline-block tabular-nums\">\n                {count + joined}\n              </motion.span>\n            </AnimatePresence>\n          </span>\n          <span className=\"-ml-2 rounded-full border border-line bg-panel2 py-1 pl-4 pr-3 text-mute\">{countLabel}</span>\n        </div>\n      </div>\n    </div>\n  )\n}\n"
    }
  ],
  "cssVars": {
    "theme": {
      "color-bg": "var(--bg)",
      "color-panel": "var(--panel)",
      "color-panel2": "var(--panel2)",
      "color-line": "var(--line)",
      "color-line2": "var(--line2)",
      "color-tx": "var(--tx)",
      "color-mute": "var(--mute)",
      "color-faint": "var(--faint)",
      "color-acc": "var(--acc)",
      "color-acc-fg": "var(--acc-fg)"
    },
    "light": {
      "bg": "#ffffff",
      "panel": "#f5f5f7",
      "panel2": "#e8e8ed",
      "line": "#e5e5ea",
      "line2": "#d2d2d7",
      "tx": "#1d1d1f",
      "mute": "#6e6e73",
      "faint": "#a1a1a6",
      "acc": "#1d1d1f",
      "acc-fg": "#ffffff"
    },
    "dark": {
      "bg": "#000000",
      "panel": "#141416",
      "panel2": "#1f1f22",
      "line": "#262628",
      "line2": "#3a3a3d",
      "tx": "#f5f5f7",
      "mute": "#a1a1a6",
      "faint": "#6e6e73",
      "acc": "#f5f5f7",
      "acc-fg": "#000000"
    }
  },
  "css": {
    ".light": {
      "--bg": "#ffffff",
      "--panel": "#f5f5f7",
      "--panel2": "#e8e8ed",
      "--line": "#e5e5ea",
      "--line2": "#d2d2d7",
      "--tx": "#1d1d1f",
      "--mute": "#6e6e73",
      "--faint": "#a1a1a6",
      "--acc": "#1d1d1f",
      "--acc-fg": "#ffffff"
    }
  }
}
