{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "waitlist-form-block",
  "title": "Waitlist Form Block",
  "description": "A waitlist signup block: one email field, then your place in line counting into view with a progress bar, an invite link to copy or share that moves you up for every friend who joins, reward tiers that unlock, and a live waiting count.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/waitlist-form-block/waitlist-form-block.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, animate, 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 WaitlistJoinResult {\n  /** Place in line. */\n  position: number;\n  /** Link people share to move up. */\n  referralUrl: string;\n}\n\nexport interface WaitlistFormBlockProps {\n  badge?: string;\n  title?: string;\n  description?: string;\n  /** People already on the list, shown under the form. */\n  initialCount?: number;\n  /** Avatars next to the count. Pass [] to hide them. */\n  avatars?: string[];\n  /** Places someone moves up for each friend who joins with their link. */\n  placesPerReferral?: number;\n  /** What people get as they move up, from the top of the list down. */\n  rewards?: { places: number; label: string }[];\n  /**\n   * Called with the email. Return { position, referralUrl } (or a promise of it). A rejection or a\n   * returned string shows an error. Without it a demo position is generated.\n   */\n  onJoin?: (email: string) => WaitlistJoinResult | string | Promise<WaitlistJoinResult | string>;\n  /** Grow the joined count now and then, so the list feels alive. */\n  liveCount?: boolean;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.6)\", faint: \"rgba(245,244,241,0.38)\", card: \"#111111\", border: \"rgba(255,255,255,0.1)\", field: \"rgba(255,255,255,0.04)\", fieldBorder: \"rgba(255,255,255,0.14)\", track: \"rgba(255,255,255,0.1)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", accent: \"#A78BFA\", error: \"#FF7A6B\", ok: \"#4ADE80\", ring: \"rgba(245,244,241,0.6)\" },\n  light: { bg: \"#FAFAF8\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.6)\", faint: \"rgba(10,10,10,0.4)\", card: \"#FFFFFF\", border: \"rgba(10,10,10,0.1)\", field: \"#FFFFFF\", fieldBorder: \"rgba(10,10,10,0.16)\", track: \"rgba(10,10,10,0.08)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", accent: \"#7C3AED\", error: \"#D93F2B\", ok: \"#16A34A\", ring: \"rgba(10,10,10,0.5)\" },\n};\n\nconst DEFAULT_REWARDS = [\n  { places: 100, label: \"First 100: lifetime 50% off\" },\n  { places: 500, label: \"Top 500: early access in February\" },\n  { places: 2000, label: \"Top 2,000: a free month\" },\n];\n\nfunction hash(s: string) {\n  let h = 2166136261;\n  for (let i = 0; i < s.length; i++) h = Math.imul(h ^ s.charCodeAt(i), 16777619);\n  return h >>> 0;\n}\n\nfunction Counter({ value, reduce }: { value: number; reduce: boolean }) {\n  const [shown, setShown] = React.useState(value);\n  const from = React.useRef(value);\n  React.useEffect(() => {\n    if (reduce) {\n      from.current = value;\n      const id = setTimeout(() => setShown(value), 0);\n      return () => clearTimeout(id);\n    }\n    const c = animate(from.current, value, { duration: 0.8, ease: [0.2, 0.7, 0.2, 1], onUpdate: (v) => setShown(Math.round(v)) });\n    from.current = value;\n    return () => c.stop();\n  }, [value, reduce]);\n  return <>{shown.toLocaleString(\"en-US\")}</>;\n}\n\nexport function WaitlistFormBlock({\n  badge = \"Launching February 2027\",\n  title = \"Be first in line for Nexora mobile\",\n  description = \"Plan from your phone, offline, with the same docs and boards. Join the waitlist and move up by inviting your team.\",\n  initialCount = 12480,\n  avatars = [\"/demo/41.webp\", \"/demo/42.webp\", \"/demo/44.webp\", \"/demo/49.webp\", \"/demo/47.webp\"],\n  placesPerReferral = 250,\n  rewards = DEFAULT_REWARDS,\n  onJoin,\n  liveCount = true,\n  theme = \"dark\",\n  className,\n}: WaitlistFormBlockProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [email, setEmail] = React.useState(\"\");\n  const [touched, setTouched] = React.useState(false);\n  const [status, setStatus] = React.useState<\"idle\" | \"loading\" | \"joined\">(\"idle\");\n  const [error, setError] = React.useState(\"\");\n  const [count, setCount] = React.useState(initialCount);\n  const [result, setResult] = React.useState<WaitlistJoinResult | null>(null);\n  const [referrals, setReferrals] = React.useState(0);\n  const [copied, setCopied] = React.useState(false);\n  const doneRef = React.useCallback((el: HTMLHeadingElement | null) => el?.focus(), []);\n  const valid = /^\\S+@\\S+\\.\\S+$/.test(email.trim());\n\n  React.useEffect(() => {\n    if (!liveCount || reduce) return;\n    const id = setInterval(() => setCount((c) => c + 1 + (c % 3)), 2600);\n    return () => clearInterval(id);\n  }, [liveCount, reduce]);\n\n  const position = result ? Math.max(1, result.position - referrals * placesPerReferral) : 0;\n  const total = Math.max(count, result?.position ?? 0);\n  const reward = rewards.find((r) => position <= r.places);\n  const nextReward = [...rewards].reverse().find((r) => position > r.places);\n  const ahead = nextReward ? Math.ceil((position - nextReward.places) / placesPerReferral) : 0;\n\n  const submit = async (e: React.FormEvent) => {\n    e.preventDefault();\n    setTouched(true);\n    setError(\"\");\n    if (!valid) return;\n    setStatus(\"loading\");\n    try {\n      const res = onJoin\n        ? await onJoin(email.trim())\n        : await new Promise<WaitlistJoinResult>((r) => setTimeout(() => r({ position: count + 1, referralUrl: `https://nexora.app/w/${hash(email.trim().toLowerCase()).toString(36).slice(0, 6)}` }), 900));\n      if (typeof res === \"string\") {\n        setError(res);\n        setStatus(\"idle\");\n        return;\n      }\n      setResult(res);\n      setCount((c) => Math.max(c, res.position));\n      setStatus(\"joined\");\n    } catch (err) {\n      setError(err instanceof Error ? err.message : \"Something went wrong. Please try again.\");\n      setStatus(\"idle\");\n    }\n  };\n\n  const copy = async () => {\n    if (!result) return;\n    try {\n      await navigator.clipboard.writeText(result.referralUrl);\n    } catch {\n      /* Clipboard may be blocked; still confirm. */\n    }\n    setCopied(true);\n    setTimeout(() => setCopied(false), 1800);\n  };\n  const share = async () => {\n    if (!result) return;\n    const data = { title, text: \"Join me on the waitlist\", url: result.referralUrl };\n    if (typeof navigator !== \"undefined\" && \"share\" in navigator) {\n      try {\n        await navigator.share(data);\n        return;\n      } catch {\n        /* Share sheet closed; fall back to copying. */\n      }\n    }\n    copy();\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\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"mx-auto max-w-3xl px-6 py-20 text-center @[640px]:py-24\">\n        {badge && (\n          <p className=\"m-0 inline-flex items-center gap-2 rounded-full border px-3 py-1 text-[12.5px]\" style={{ borderColor: p.border, color: p.muted }}>\n            <span className=\"relative flex h-2 w-2\" aria-hidden=\"true\">\n              {!reduce && <span className=\"absolute inset-0 animate-ping rounded-full opacity-60\" style={{ background: p.accent }} />}\n              <span className=\"relative h-2 w-2 rounded-full\" style={{ background: p.accent }} />\n            </span>\n            {badge}\n          </p>\n        )}\n        <h2 className=\"mx-auto mt-5 mb-0 max-w-[16ch] text-[34px] leading-[1.06] font-semibold tracking-[-0.035em] @[640px]:text-[54px]\">{title}</h2>\n        {description && <p className=\"mx-auto mt-4 mb-0 max-w-[520px] text-[16px] leading-[1.6] @[640px]:text-[17px]\" style={{ color: p.muted }}>{description}</p>}\n\n        <div className=\"mx-auto mt-9 max-w-[520px] text-left\">\n          <AnimatePresence mode=\"wait\" initial={false}>\n            {status !== \"joined\" ? (\n              <motion.form key=\"form\" noValidate onSubmit={submit} initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={reduce ? undefined : { opacity: 0, y: -8 }}>\n                <label htmlFor={`${uid}-e`} className=\"sr-only\">\n                  Email\n                </label>\n                <div className=\"flex flex-col gap-2 rounded-2xl border p-1.5 transition-colors @[480px]:flex-row\" style={{ borderColor: touched && !valid ? p.error : p.fieldBorder, background: p.field }}>\n                  <input\n                    id={`${uid}-e`}\n                    type=\"email\"\n                    autoComplete=\"email\"\n                    inputMode=\"email\"\n                    placeholder=\"you@company.com\"\n                    value={email}\n                    disabled={status === \"loading\"}\n                    aria-invalid={(touched && !valid) || undefined}\n                    aria-describedby={`${uid}-err`}\n                    onChange={(e) => {\n                      setEmail(e.target.value);\n                      setError(\"\");\n                    }}\n                    className=\"h-11 min-w-0 flex-1 rounded-xl border-0 bg-transparent px-3.5 text-[16px] outline-none focus-visible:ring-2\"\n                    style={{ color: p.text, [\"--tw-ring-color\" as string]: p.ring }}\n                  />\n                  <button type=\"submit\" disabled={status === \"loading\"} className={cn(\"flex h-11 shrink-0 cursor-pointer items-center justify-center gap-2 rounded-xl border-0 px-5 text-[15px] font-medium transition-opacity hover:opacity-90 disabled:cursor-wait\", focus)} style={{ background: p.on, color: p.onText, ...ring }}>\n                    {status === \"loading\" ? (\n                      <>\n                        <motion.span className=\"h-4 w-4 rounded-full border-2 border-current border-t-transparent\" animate={reduce ? undefined : { rotate: 360 }} transition={{ repeat: Infinity, duration: 0.8, ease: \"linear\" }} aria-hidden=\"true\" />\n                        Joining...\n                      </>\n                    ) : (\n                      \"Join the waitlist\"\n                    )}\n                  </button>\n                </div>\n                <p id={`${uid}-err`} role=\"alert\" className=\"m-0 mt-2 min-h-[20px] text-center text-[13px]\" style={{ color: p.error }}>\n                  {touched && !valid ? \"Add a valid email address.\" : error}\n                </p>\n              </motion.form>\n            ) : (\n              result && (\n                <motion.div key=\"joined\" role=\"status\" initial={reduce ? false : { opacity: 0, y: 12, scale: 0.98 }} animate={{ opacity: 1, y: 0, scale: 1 }} transition={{ type: \"spring\", stiffness: 240, damping: 24 }} className=\"overflow-hidden rounded-2xl border\" style={{ background: p.card, borderColor: p.border }}>\n                  <div className=\"p-5 text-center @[480px]:p-6\">\n                    <p className=\"m-0 text-[13px]\" style={{ color: p.muted }}>\n                      You are on the list\n                    </p>\n                    <h3 ref={doneRef} tabIndex={-1} className=\"m-0 mt-1 text-[48px] leading-none font-semibold tracking-[-0.04em] tabular-nums outline-none @[480px]:text-[60px]\">\n                      #<Counter value={position} reduce={reduce} />\n                    </h3>\n                    <p className=\"m-0 mt-2 text-[13.5px]\" style={{ color: p.faint }}>\n                      of <Counter value={total} reduce={reduce} /> people\n                    </p>\n                    <div className=\"mt-5 h-2 overflow-hidden rounded-full\" style={{ background: p.track }} aria-hidden=\"true\">\n                      <motion.div className=\"h-full rounded-full\" style={{ background: `linear-gradient(90deg, ${p.accent}, ${p.on})` }} initial={false} animate={{ width: `${Math.max(3, (1 - (position - 1) / total) * 100)}%` }} transition={{ duration: reduce ? 0 : 0.8, ease: [0.2, 0.7, 0.2, 1] }} />\n                    </div>\n                    <p className=\"m-0 mt-3 text-[13.5px]\" style={{ color: p.text }} aria-live=\"polite\">\n                      {[reward && `Unlocked: ${reward.label}.`, nextReward && `Invite ${ahead} ${ahead === 1 ? \"friend\" : \"friends\"} to reach: ${nextReward.label}.`].filter(Boolean).join(\" \")}\n                    </p>\n                  </div>\n                  <div className=\"border-t p-5 @[480px]:p-6\" style={{ borderColor: p.border }}>\n                    <p className=\"m-0 text-[13.5px]\" style={{ color: p.muted }}>\n                      Move up {placesPerReferral} places for every friend who joins with your link.\n                    </p>\n                    <div className=\"mt-3 flex flex-wrap gap-2 @[480px]:flex-nowrap\">\n                      <label htmlFor={`${uid}-link`} className=\"sr-only\">\n                        Your invite link\n                      </label>\n                      <input id={`${uid}-link`} readOnly value={result.referralUrl} onFocus={(e) => e.target.select()} className=\"h-10 min-w-0 flex-1 basis-full rounded-lg border px-3 font-mono text-[13px] @[480px]:basis-auto outline-none focus-visible:ring-2\" style={{ background: p.field, borderColor: p.fieldBorder, color: p.text, [\"--tw-ring-color\" as string]: p.ring }} />\n                      <button type=\"button\" onClick={copy} className={cn(\"h-10 flex-1 cursor-pointer rounded-lg border px-3.5 text-[13px] font-medium @[480px]:flex-none\", focus)} style={{ borderColor: p.fieldBorder, background: \"transparent\", color: p.text, ...ring }}>\n                        <span aria-live=\"polite\">{copied ? \"Copied\" : \"Copy\"}</span>\n                      </button>\n                      <button type=\"button\" onClick={share} className={cn(\"h-10 flex-1 cursor-pointer rounded-lg border-0 px-3.5 text-[13px] font-medium @[480px]:flex-none\", focus)} style={{ background: p.on, color: p.onText, ...ring }}>\n                        Share\n                      </button>\n                    </div>\n                    <div className=\"mt-4 flex items-center justify-between gap-3 text-[13px]\">\n                      <span style={{ color: p.faint }} className=\"tabular-nums\">\n                        {referrals} {referrals === 1 ? \"friend\" : \"friends\"} joined\n                      </span>\n                      <button type=\"button\" onClick={() => setReferrals((n) => n + 1)} className={cn(\"cursor-pointer rounded border-0 bg-transparent p-0 underline underline-offset-4\", focus)} style={{ color: p.muted, ...ring }}>\n                        Simulate a friend joining\n                      </button>\n                    </div>\n                  </div>\n                </motion.div>\n              )\n            )}\n          </AnimatePresence>\n        </div>\n\n        <div className=\"mt-6 flex items-center justify-center gap-3\">\n          {avatars.length > 0 && (\n            <div className=\"flex -space-x-2\">\n              {avatars.slice(0, 5).map((src) => (\n                // eslint-disable-next-line @next/next/no-img-element\n                <img key={src} src={src} alt=\"\" width={28} height={28} className=\"h-7 w-7 rounded-full object-cover\" style={{ boxShadow: `0 0 0 2px ${p.bg}` }} />\n              ))}\n            </div>\n          )}\n          <p className=\"m-0 text-[13.5px] tabular-nums\" style={{ color: p.muted }} aria-live=\"off\">\n            <span style={{ color: p.text }}>\n              <Counter value={count} reduce={reduce} />\n            </span>{\" \"}\n            people waiting\n          </p>\n        </div>\n\n        {rewards.length > 0 && (\n          <ul className=\"m-0 mx-auto mt-10 grid max-w-[640px] list-none grid-cols-1 gap-2 p-0 text-left @[560px]:grid-cols-3\">\n            {rewards.map((r) => {\n              const won = !!result && position <= r.places;\n              return (\n                <li key={r.label} className=\"rounded-xl border p-3.5 transition-colors\" style={{ borderColor: won ? p.accent : p.border, background: won ? p.field : \"transparent\" }}>\n                  <span className=\"flex items-center gap-2 text-[12px] tabular-nums\" style={{ color: won ? p.accent : p.faint }}>\n                    {won ? \"✓ Unlocked\" : `Top ${r.places.toLocaleString(\"en-US\")}`}\n                  </span>\n                  <span className=\"mt-1 block text-[13.5px] leading-[1.4]\" style={{ color: p.text }}>\n                    {r.label.replace(/^[^:]+:\\s*/, \"\")}\n                  </span>\n                </li>\n              );\n            })}\n          </ul>\n        )}\n      </div>\n    </section>\n  );\n}\n\nexport default WaitlistFormBlock;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}