{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "waitlist",
  "type": "registry:block",
  "title": "Waitlist",
  "description": "A join-the-line card: your position rolls down digit by digit, a referral link to copy, and friends who sign up drop into slots while you jump toward the next wave.",
  "categories": [
    "block",
    "Auth"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/button.json",
    "https://coss.com/ui/r/input.json"
  ],
  "files": [
    {
      "path": "registry/devl/waitlist.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport { ArrowRightIcon, CheckIcon, CopyIcon, LinkIcon, PartyPopperIcon, PlusIcon } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { type FormEvent, useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport { Button } from \"@/components/ui/button\";\nimport { Input } from \"@/components/ui/input\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface WaitlistReferral {\n  id: string;\n  name: string;\n  tone?: string;\n}\n\nexport interface WaitlistTicket {\n  position: number;\n  total: number;\n  link: string;\n}\n\nexport interface WaitlistWave {\n  label: string;\n  upTo: number;\n}\n\nexport interface WaitlistProps {\n  product?: string;\n  eyebrow?: string;\n  title?: string;\n  subtitle?: string;\n  waiting?: number;\n  spotsPerReferral?: number;\n  goal?: number;\n  waves?: WaitlistWave[];\n  referrals?: WaitlistReferral[];\n  defaultEmail?: string;\n  onJoin?: (email: string) => Promise<WaitlistTicket>;\n  className?: string;\n}\n\nconst ease = [0.23, 1, 0.32, 1] as const;\nconst press = \"transition-[box-shadow,scale,background-color] duration-150 active:scale-[0.97]\";\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/;\nconst FALLBACK_TONES = [\n  \"bg-sky-500/15 text-sky-700 dark:text-sky-300\",\n  \"bg-rose-500/15 text-rose-700 dark:text-rose-300\",\n  \"bg-amber-500/15 text-amber-800 dark:text-amber-300\",\n  \"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300\",\n];\n\nfunction initials(name: string) {\n  return name\n    .split(\" \")\n    .map((w) => w[0])\n    .join(\"\")\n    .slice(0, 2)\n    .toUpperCase();\n}\n\nfunction useMeasuredHeight<T extends HTMLElement>() {\n  const ref = useRef<T>(null);\n  const [height, setHeight] = useState<number | \"auto\">(\"auto\");\n  useLayoutEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const ro = new ResizeObserver(() => setHeight(el.offsetHeight));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n  return [ref, height] as const;\n}\n\nfunction Digit({ value }: { value: number }) {\n  const reduce = useReducedMotion();\n  return (\n    <span aria-hidden className=\"relative inline-block h-[1.1em] w-[0.62em] overflow-hidden\">\n      <motion.span\n        animate={{ y: `${-value * 1.1}em` }}\n        className=\"absolute inset-x-0 top-0 flex flex-col items-center\"\n        initial={false}\n        transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 140, damping: 22 }}\n      >\n        {Array.from({ length: 10 }, (_, n) => (\n          <span className=\"block h-[1.1em] leading-[1.1em]\" key={n}>\n            {n}\n          </span>\n        ))}\n      </motion.span>\n    </span>\n  );\n}\n\nfunction Rolling({ value, className }: { value: number; className?: string }) {\n  const text = value.toLocaleString(\"en-US\");\n  const chars = text.split(\"\");\n  return (\n    <span className={cn(\"inline-flex tabular-nums leading-[1.1em]\", className)}>\n      <span className=\"sr-only\">{text}</span>\n      {chars.map((ch, i) => {\n        const key = chars.length - i;\n        return /\\d/.test(ch) ? (\n          <Digit key={`d${key}`} value={Number(ch)} />\n        ) : (\n          <span aria-hidden className=\"w-[0.3em] text-center\" key={`s${key}`}>\n            {ch}\n          </span>\n        );\n      })}\n    </span>\n  );\n}\n\nexport function Waitlist({\n  product = \"Parcel\",\n  eyebrow = \"Early access\",\n  title = \"Notes that file themselves.\",\n  subtitle = \"Parcel reads what you write and sorts it into the right project, so your inbox of ideas stays at zero.\",\n  waiting = 6212,\n  spotsPerReferral = 250,\n  goal = 3,\n  waves = [\n    { label: \"Wave 1\", upTo: 500 },\n    { label: \"Wave 2\", upTo: 2000 },\n    { label: \"Wave 3\", upTo: Number.POSITIVE_INFINITY },\n  ],\n  referrals = [],\n  defaultEmail = \"\",\n  onJoin = async () => ({ position: waiting + 1, total: waiting + 1, link: \"parcel.so/r/you\" }),\n  className,\n}: WaitlistProps) {\n  const reduce = useReducedMotion();\n  const uid = useId();\n  const [email, setEmail] = useState(defaultEmail);\n  const [error, setError] = useState<string>();\n  const [busy, setBusy] = useState(false);\n  const [ticket, setTicket] = useState<WaitlistTicket | null>(null);\n  const [copied, setCopied] = useState(false);\n  const [shown, setShown] = useState<number | null>(null);\n  const [cardRef, cardHeight] = useMeasuredHeight<HTMLDivElement>();\n\n  const target = ticket ? Math.max(1, ticket.position - referrals.length * spotsPerReferral) : 0;\n  const waveIndex = waves.findIndex((w) => target <= w.upTo);\n  const wave = waves[waveIndex];\n  const nextWave = waveIndex > 0 ? waves[waveIndex - 1] : undefined;\n\n  useEffect(() => {\n    if (!ticket) return;\n    if (shown === null) {\n      setShown(ticket.total);\n      const t = setTimeout(() => setShown(target), reduce ? 0 : 120);\n      return () => clearTimeout(t);\n    }\n    setShown(target);\n  }, [ticket, target]);\n\n  useEffect(() => {\n    if (!copied) return;\n    const t = setTimeout(() => setCopied(false), 1600);\n    return () => clearTimeout(t);\n  }, [copied]);\n\n  const submit = async (event: FormEvent) => {\n    event.preventDefault();\n    if (!EMAIL.test(email.trim())) {\n      setError(\"Enter an email address so we can save your spot.\");\n      return;\n    }\n    setError(undefined);\n    setBusy(true);\n    const t = await onJoin(email.trim());\n    setBusy(false);\n    setTicket(t);\n  };\n\n  const copyLink = async () => {\n    if (!ticket) return;\n    try {\n      await navigator.clipboard.writeText(`https://${ticket.link}`);\n    } catch {\n      // Blocked clipboard (e.g. sandboxed iframe): the link is still selectable in the field.\n    }\n    setCopied(true);\n  };\n\n  const latest = referrals[referrals.length - 1];\n  const prevWave = waves.findIndex((w) => target + spotsPerReferral <= w.upTo);\n  const promoted = latest && prevWave !== waveIndex;\n  const progressTo = ticket && nextWave ? Math.min(1, Math.max(0.03, (ticket.total - target) / Math.max(1, ticket.total - nextWave.upTo))) : 1;\n\n  return (\n    <section className={cn(\"mx-auto grid w-full max-w-[1000px] items-center gap-8 md:grid-cols-[1fr_440px] md:gap-12\", className)}>\n      <div className=\"min-w-0\">\n        <span className=\"inline-flex items-center gap-1.5 rounded-full border bg-card px-2.5 py-1 font-medium text-xs shadow-xs/5\">\n          <span className=\"relative flex size-1.5\">\n            <span className=\"absolute inset-0 animate-ping rounded-full bg-success/60 motion-reduce:hidden\" />\n            <span className=\"relative size-1.5 rounded-full bg-success\" />\n          </span>\n          {eyebrow}\n        </span>\n        <h2 className=\"mt-4 text-balance font-semibold text-3xl tracking-tight sm:text-4xl\">{title}</h2>\n        <p className=\"mt-3 max-w-[44ch] text-pretty text-muted-foreground\">{subtitle}</p>\n        <div className=\"mt-6 flex items-center gap-3\">\n          <div className=\"flex -space-x-1.5\">\n            {[\"Ines Vale\", \"Kofi Mensah\", \"Lena Park\", \"Ravi Shah\"].map((n, i) => (\n              <span className=\"rounded-full bg-background ring-2 ring-background\" key={n}>\n                <span className={cn(\"flex size-7 items-center justify-center rounded-full font-medium text-[0.625rem]\", FALLBACK_TONES[i])}>\n                  {initials(n)}\n                </span>\n              </span>\n            ))}\n          </div>\n          <p className=\"text-muted-foreground text-sm\">\n            <span className=\"font-medium text-foreground tabular-nums\">{(ticket?.total ?? waiting).toLocaleString(\"en-US\")}</span> people waiting\n          </p>\n        </div>\n      </div>\n\n      <motion.div\n        animate={{ height: cardHeight }}\n        className=\"box-content overflow-hidden rounded-2xl border bg-card text-card-foreground shadow-xs/5\"\n        initial={false}\n        transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 380, damping: 38 }}\n      >\n        <div ref={cardRef}>\n        <AnimatePresence initial={false} mode=\"wait\">\n          {!ticket ? (\n            <motion.form\n              animate={{ opacity: 1 }}\n              className=\"p-5 sm:p-6\"\n              exit={{ opacity: 0, transition: { duration: 0.12 } }}\n              initial={false}\n              key=\"join\"\n              noValidate\n              onSubmit={submit}\n            >\n              <p className=\"font-medium text-sm\">Save your spot in line</p>\n              <p className=\"mt-1 text-muted-foreground text-sm\">One email when it’s your turn. Nothing else.</p>\n              <label className=\"sr-only\" htmlFor={`${uid}-email`}>\n                Email\n              </label>\n              <div className=\"mt-4 flex flex-col gap-2 sm:flex-row\">\n                <Input\n                  aria-describedby={error ? `${uid}-err` : undefined}\n                  aria-invalid={error ? true : undefined}\n                  autoComplete=\"email\"\n                  className=\"flex-1\"\n                  id={`${uid}-email`}\n                  onChange={(e) => {\n                    setEmail(e.target.value);\n                    if (error) setError(undefined);\n                  }}\n                  placeholder=\"you@studio.com\"\n                  type=\"email\"\n                  value={email}\n                />\n                <Button className={press} loading={busy} type=\"submit\">\n                  Join waitlist\n                  <ArrowRightIcon />\n                </Button>\n              </div>\n              <AnimatePresence initial={false}>\n                {error && (\n                  <motion.p\n                    animate={{ height: \"auto\", opacity: 1 }}\n                    className=\"overflow-hidden text-destructive-foreground text-xs\"\n                    exit={{ height: 0, opacity: 0 }}\n                    id={`${uid}-err`}\n                    initial={{ height: 0, opacity: 0 }}\n                    transition={{ duration: 0.18, ease }}\n                  >\n                    <span className=\"block pt-2\">{error}</span>\n                  </motion.p>\n                )}\n              </AnimatePresence>\n            </motion.form>\n          ) : (\n            <motion.div\n              animate={{ opacity: 1, y: 0 }}\n              initial={reduce ? { opacity: 0 } : { opacity: 0, y: 8 }}\n              key=\"ticket\"\n              transition={{ duration: 0.26, ease }}\n            >\n              <div className=\"p-5 sm:p-6\">\n                <div className=\"flex items-start justify-between gap-3\">\n                  <div>\n                    <p className=\"flex items-center gap-1.5 font-medium text-sm\">\n                      <CheckIcon className=\"size-4 text-success-foreground\" strokeWidth={2.5} />\n                      You’re on the list\n                    </p>\n                    <p className=\"mt-0.5 text-muted-foreground text-xs\">{email.trim()}</p>\n                  </div>\n                  <AnimatePresence initial={false} mode=\"popLayout\">\n                    <motion.span\n                      animate={{ opacity: 1, scale: 1 }}\n                      className={cn(\n                        \"shrink-0 rounded-full px-2 py-0.5 font-medium text-xs\",\n                        waveIndex === 0\n                          ? \"bg-success/12 text-success-foreground\"\n                          : waveIndex === 1\n                            ? \"bg-info/12 text-info-foreground\"\n                            : \"bg-muted text-muted-foreground\",\n                      )}\n                      exit={{ opacity: 0, scale: 0.9 }}\n                      initial={{ opacity: 0, scale: 0.9 }}\n                      key={wave?.label}\n                      transition={{ duration: 0.2, ease }}\n                    >\n                      {wave?.label}\n                    </motion.span>\n                  </AnimatePresence>\n                </div>\n\n                <div className=\"relative mt-5 flex items-end gap-2\">\n                  <span className=\"flex font-semibold text-5xl leading-[1.1em] tracking-tight\">\n                    <span aria-hidden className=\"me-0.5 text-muted-foreground/60\">#</span>\n                    <Rolling value={shown ?? ticket.total} />\n                  </span>\n                  <span className=\"mb-1.5 text-muted-foreground text-sm tabular-nums\">of {ticket.total.toLocaleString(\"en-US\")}</span>\n                  <AnimatePresence>\n                    {latest && (\n                      <motion.span\n                        animate={{ opacity: [0, 1, 1, 0], y: [6, 0, -4, -10] }}\n                        className=\"pointer-events-none absolute top-0 right-0 rounded-full bg-success/12 px-2 py-0.5 font-medium text-success-foreground text-xs tabular-nums\"\n                        initial={{ opacity: 0 }}\n                        key={latest.id}\n                        transition={{ duration: reduce ? 0.01 : 2.2, times: [0, 0.12, 0.8, 1], ease: \"easeOut\" }}\n                      >\n                        ↑ {spotsPerReferral} spots\n                      </motion.span>\n                    )}\n                  </AnimatePresence>\n                </div>\n\n                {nextWave ? (\n                  <div className=\"mt-4\">\n                    <div className=\"flex justify-between text-muted-foreground text-xs\">\n                      <span>\n                        <span className=\"text-foreground tabular-nums\">{Math.max(0, target - nextWave.upTo).toLocaleString(\"en-US\")}</span> spots\n                        to {nextWave.label}\n                      </span>\n                      <span className=\"tabular-nums\">#{nextWave.upTo.toLocaleString(\"en-US\")}</span>\n                    </div>\n                    <div className=\"mt-2 h-1.5 overflow-hidden rounded-full bg-muted\">\n                      <motion.div\n                        animate={{ scaleX: progressTo }}\n                        className=\"h-full origin-left rounded-full bg-primary\"\n                        initial={{ scaleX: 0 }}\n                        transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 120, damping: 24 }}\n                      />\n                    </div>\n                  </div>\n                ) : (\n                  <p className=\"mt-4 flex items-center gap-2 rounded-xl bg-success/10 px-3 py-2 text-sm text-success-foreground\">\n                    <PartyPopperIcon className=\"size-4\" />\n                    You’re in the first wave. Watch your inbox.\n                  </p>\n                )}\n              </div>\n\n              <div className=\"border-t bg-muted/40 p-5 sm:p-6\">\n                <p className=\"font-medium text-sm\">Skip ahead</p>\n                <p className=\"mt-0.5 text-pretty text-muted-foreground text-sm\">\n                  Every friend who joins with your link moves you up {spotsPerReferral} spots.\n                </p>\n                <div className=\"mt-3 flex items-center gap-2\">\n                  <div className=\"flex h-9 min-w-0 flex-1 items-center gap-2 rounded-lg border bg-background px-3 text-sm sm:h-8 dark:bg-input/32\">\n                    <LinkIcon className=\"size-3.5 shrink-0 text-muted-foreground\" />\n                    <span className=\"truncate font-mono text-[0.8125rem]\">{ticket.link}</span>\n                  </div>\n                  <Button className={cn(\"w-[88px]\", press)} onClick={copyLink} variant=\"outline\">\n                    <AnimatePresence initial={false} mode=\"popLayout\">\n                      <motion.span\n                        animate={{ opacity: 1, y: 0 }}\n                        className=\"flex items-center gap-1.5\"\n                        exit={{ opacity: 0, y: -6 }}\n                        initial={{ opacity: 0, y: 6 }}\n                        key={copied ? \"y\" : \"n\"}\n                        transition={{ duration: 0.15, ease }}\n                      >\n                        {copied ? <CheckIcon className=\"text-success-foreground\" /> : <CopyIcon />}\n                        {copied ? \"Copied\" : \"Copy\"}\n                      </motion.span>\n                    </AnimatePresence>\n                  </Button>\n                </div>\n\n                <div className=\"mt-4 flex items-center gap-3\">\n                  <ul aria-label=\"Friends who joined\" className=\"flex gap-2\">\n                    {Array.from({ length: goal }, (_, i) => {\n                      const r = referrals[i];\n                      return (\n                        <li className=\"relative size-9\" key={i}>\n                          <span className=\"absolute inset-0 flex items-center justify-center rounded-full border border-dashed border-foreground/20 text-muted-foreground/60\">\n                            <PlusIcon className=\"size-3.5\" />\n                          </span>\n                          <AnimatePresence>\n                            {r && (\n                              <motion.span\n                                animate={{ scale: 1, opacity: 1 }}\n                                className={cn(\n                                  \"absolute inset-0 flex items-center justify-center rounded-full bg-card font-medium text-xs ring-2 ring-card\",\n                                )}\n                                initial={reduce ? { opacity: 0 } : { scale: 0.6, opacity: 0 }}\n                                transition={{ type: \"spring\", stiffness: 500, damping: 26 }}\n                              >\n                                <span\n                                  className={cn(\n                                    \"flex size-full items-center justify-center rounded-full\",\n                                    r.tone ?? FALLBACK_TONES[i % FALLBACK_TONES.length],\n                                  )}\n                                  title={r.name}\n                                >\n                                  {initials(r.name)}\n                                </span>\n                              </motion.span>\n                            )}\n                          </AnimatePresence>\n                        </li>\n                      );\n                    })}\n                  </ul>\n                  <div aria-live=\"polite\" className=\"min-w-0 text-xs\">\n                    <p className=\"font-medium tabular-nums\">\n                      {Math.min(referrals.length, goal)} of {goal} friends joined\n                    </p>\n                    <div className=\"relative h-4 overflow-hidden\">\n                      <AnimatePresence initial={false} mode=\"popLayout\">\n                        <motion.p\n                          animate={{ opacity: 1, y: 0 }}\n                          className=\"truncate text-muted-foreground\"\n                          exit={{ opacity: 0, y: -10 }}\n                          initial={{ opacity: 0, y: 10 }}\n                          key={latest?.id ?? \"none\"}\n                          transition={{ duration: 0.22, ease }}\n                        >\n                          {latest\n                            ? promoted\n                              ? `${latest.name.split(\" \")[0]} joined, and you moved up to ${wave?.label}`\n                              : `${latest.name.split(\" \")[0]} just joined with your link`\n                            : \"Share your link to fill these in\"}\n                        </motion.p>\n                      </AnimatePresence>\n                    </div>\n                  </div>\n                </div>\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n        </div>\n      </motion.div>\n    </section>\n  );\n}\n"
    }
  ]
}