{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "back-in-stock-notify",
  "title": "Back-in-Stock Notify",
  "description": "A product buy box where picking a sold-out size swaps Add to cart for a restock alert: expected date and people waiting, an Email or Text message switch, validation, a half-size-either-side option and a ringing-bell confirmation, with alert badges on sizes and removable alert chips.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/back-in-stock-notify/back-in-stock-notify.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, LayoutGroup, 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 StockSize {\n  label: string;\n  stock: number;\n  /** Shown when sold out, e.g. \"Dec 12\". */\n  restock?: string;\n  /** People already waiting for this size. */\n  waiting?: number;\n}\nexport interface StockAlert {\n  size: string;\n  channel: \"email\" | \"sms\";\n  contact: string;\n  similar: boolean;\n}\nexport interface BackInStockNotifyProps {\n  product?: { name: string; price: number; was?: number; image: string; color: string };\n  sizes?: StockSize[];\n  currency?: string;\n  defaultSize?: string;\n  onSubscribe?: (alert: StockAlert) => void | Promise<void>;\n  onCancel?: (alert: StockAlert) => void;\n  onAdd?: (size: string) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: {\n    bg: \"#0A0A0A\",\n    card: \"#141414\",\n    field: \"#0F0F0F\",\n    title: \"#FFFFFF\",\n    muted: \"rgba(255,255,255,0.45)\",\n    body: \"rgba(255,255,255,0.62)\",\n    line: \"rgba(255,255,255,0.12)\",\n    lineHi: \"rgba(255,255,255,0.32)\",\n    tile: \"#F1F1F1\",\n    accent: \"#7CDE6A\",\n    accentText: \"#0B1A08\",\n    accentSoft: \"rgba(124,222,106,0.1)\",\n    amber: \"#F5B44A\",\n    buttonBg: \"#FFFFFF\",\n    buttonText: \"#111111\",\n    ghost: \"rgba(255,255,255,0.07)\",\n    error: \"#FF7A70\",\n    scheme: \"dark\" as const,\n  },\n  light: {\n    bg: \"#FFFFFF\",\n    card: \"#F7F7F7\",\n    field: \"#FFFFFF\",\n    title: \"#111111\",\n    muted: \"rgba(0,0,0,0.45)\",\n    body: \"rgba(0,0,0,0.62)\",\n    line: \"rgba(0,0,0,0.1)\",\n    lineHi: \"rgba(0,0,0,0.3)\",\n    tile: \"#F1F1F1\",\n    accent: \"#2F9E44\",\n    accentText: \"#FFFFFF\",\n    accentSoft: \"rgba(47,158,68,0.08)\",\n    amber: \"#B86E00\",\n    buttonBg: \"#111111\",\n    buttonText: \"#FFFFFF\",\n    ghost: \"rgba(0,0,0,0.05)\",\n    error: \"#D93025\",\n    scheme: \"light\" as const,\n  },\n};\n\nconst PRODUCT = { name: \"Running Shoes\", price: 99, was: 149, image: \"/demo/running-shoes.webp\", color: \"Cloud grey\" };\nconst SIZES: StockSize[] = [\n  { label: \"7\", stock: 6 },\n  { label: \"7.5\", stock: 4 },\n  { label: \"8\", stock: 9 },\n  { label: \"8.5\", stock: 0, restock: \"early January\", waiting: 12 },\n  { label: \"9\", stock: 2 },\n  { label: \"9.5\", stock: 7 },\n  { label: \"10\", stock: 3 },\n  { label: \"10.5\", stock: 0, restock: \"Dec 12\", waiting: 38 },\n  { label: \"11\", stock: 0, restock: \"Dec 12\", waiting: 21 },\n  { label: \"12\", stock: 0, waiting: 6 },\n];\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/;\nconst BELL = \"M6 9a6 6 0 1 1 12 0c0 4.5 1.6 6.3 2.4 7.1.3.3.1.9-.4.9H4c-.5 0-.7-.6-.4-.9C4.4 15.3 6 13.5 6 9Z\";\n\nfunction Bell({ ring, color, size = 18 }: { ring: number; color: string; size?: number }) {\n  const reduce = useReducedMotion();\n  return (\n    <motion.svg\n      key={ring}\n      width={size}\n      height={size}\n      viewBox=\"0 0 24 24\"\n      fill=\"none\"\n      stroke={color}\n      strokeWidth=\"1.9\"\n      strokeLinecap=\"round\"\n      strokeLinejoin=\"round\"\n      style={{ transformOrigin: \"50% 10%\" }}\n      initial={false}\n      animate={reduce || !ring ? undefined : { rotate: [0, 18, -14, 10, -6, 0] }}\n      transition={{ duration: 0.8 }}\n      aria-hidden=\"true\"\n    >\n      <path d={BELL} />\n      <path d=\"M10 20.5a2.2 2.2 0 0 0 4 0\" />\n    </motion.svg>\n  );\n}\n\nexport function BackInStockNotify({ product = PRODUCT, sizes = SIZES, currency = \"$\", defaultSize = \"9.5\", onSubscribe, onCancel, onAdd, theme = \"dark\", className }: BackInStockNotifyProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [size, setSize] = React.useState(defaultSize);\n  const [channel, setChannel] = React.useState<\"email\" | \"sms\">(\"email\");\n  const [email, setEmail] = React.useState(\"\");\n  const [phone, setPhone] = React.useState(\"\");\n  const [similar, setSimilar] = React.useState(true);\n  const [tried, setTried] = React.useState(false);\n  const [sending, setSending] = React.useState(false);\n  const [alerts, setAlerts] = React.useState<StockAlert[]>([]);\n  const [ring, setRing] = React.useState(0);\n  const [added, setAdded] = React.useState<string | null>(null);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n\n  const cur = sizes.find((s) => s.label === size) ?? sizes[0];\n  const soldOut = cur.stock === 0;\n  const alert = alerts.find((a) => a.size === cur.label);\n  const contact = channel === \"email\" ? email.trim() : phone.trim();\n  const valid = channel === \"email\" ? EMAIL.test(contact) : contact.replace(/\\D/g, \"\").length >= 7;\n  const err = tried && !valid ? (channel === \"email\" ? \"Enter a valid email address.\" : \"Enter a phone number with at least 7 digits.\") : \"\";\n\n  const pick = (s: StockSize) => {\n    setSize(s.label);\n    setTried(false);\n    setAdded(null);\n  };\n  const subscribe = async (e: React.FormEvent) => {\n    e.preventDefault();\n    setTried(true);\n    if (!valid) {\n      inputRef.current?.focus();\n      return;\n    }\n    const a: StockAlert = { size: cur.label, channel, contact, similar };\n    setSending(true);\n    await Promise.all([onSubscribe?.(a), new Promise((r) => setTimeout(r, reduce ? 0 : 700))]);\n    setSending(false);\n    setTried(false);\n    setAlerts((list) => [...list.filter((x) => x.size !== a.size), a]);\n    setRing((r) => r + 1);\n  };\n  const cancel = (a: StockAlert) => {\n    setAlerts((list) => list.filter((x) => x.size !== a.size));\n    onCancel?.(a);\n  };\n\n  const ease = [0.22, 1, 0.36, 1] as const;\n  const fieldCls = \"h-11 w-full rounded-xl border px-3.5 text-[14px] outline-none transition-colors placeholder:opacity-60 focus:border-current\";\n\n  return (\n    <section className={cn(\"w-full px-4 py-12 sm:px-8 sm:py-16\", className)} style={{ background: p.bg, color: p.body, colorScheme: p.scheme }}>\n      <div className=\"mx-auto grid w-full max-w-[980px] gap-8 md:grid-cols-[minmax(0,1fr)_minmax(0,1.05fr)] md:gap-12\">\n        {/* Photo */}\n        <div className=\"relative aspect-[4/3] overflow-hidden rounded-2xl md:aspect-auto md:min-h-[420px]\" style={{ background: p.tile }}>\n          {/* eslint-disable-next-line @next/next/no-img-element -- plain img keeps the block framework-agnostic */}\n          <img\n            src={product.image}\n            alt={product.name}\n            width={1344}\n            height={752}\n            className=\"absolute inset-0 h-full w-full object-cover transition-[filter] duration-300\"\n            style={{ transform: \"scale(1.12)\", filter: soldOut ? \"grayscale(1) opacity(0.55)\" : \"none\" }}\n          />\n          <AnimatePresence>\n            {soldOut ? (\n              <motion.span key=\"so\" initial={reduce ? false : { opacity: 0, y: -6 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: -6 }} className=\"absolute top-3 left-3 rounded-full bg-[#111111] px-2.5 py-1 text-[12px] font-semibold text-white\">\n                US {cur.label} sold out\n              </motion.span>\n            ) : null}\n          </AnimatePresence>\n        </div>\n\n        {/* Buy box */}\n        <div className=\"min-w-0\">\n          <p className=\"text-[12px] font-medium tracking-[0.14em] uppercase\" style={{ color: p.muted }}>\n            Northline · {product.color}\n          </p>\n          <h2 className=\"mt-2 text-[28px] font-semibold tracking-tight sm:text-[32px]\" style={{ color: p.title }}>\n            {product.name}\n          </h2>\n          <p className=\"mt-1.5 text-[18px] tabular-nums\">\n            <span className=\"font-semibold\" style={{ color: p.title }}>\n              {currency}\n              {product.price.toFixed(2)}\n            </span>\n            {product.was ? (\n              <span className=\"ml-2.5 text-[14px] line-through\" style={{ color: p.muted }}>\n                {currency}\n                {product.was.toFixed(2)}\n              </span>\n            ) : null}\n          </p>\n\n          <p id={`${uid}-sz`} className=\"mt-6 mb-2.5 text-[13px]\" style={{ color: p.muted }}>\n            Size <span style={{ color: p.title }}>US {cur.label}</span>\n          </p>\n          <div role=\"radiogroup\" aria-labelledby={`${uid}-sz`} className=\"grid grid-cols-5 gap-2\">\n            {sizes.map((s) => {\n              const on = s.label === size;\n              const out = s.stock === 0;\n              const watching = alerts.some((a) => a.size === s.label);\n              return (\n                <button\n                  key={s.label}\n                  type=\"button\"\n                  role=\"radio\"\n                  aria-checked={on}\n                  aria-label={`US ${s.label}${out ? (watching ? \", sold out, alert set\" : \", sold out\") : \"\"}`}\n                  onClick={() => pick(s)}\n                  className=\"relative h-11 rounded-xl border text-[14px] font-medium tabular-nums transition-colors\"\n                  style={{ borderColor: on ? p.title : p.line, background: on ? (out ? p.ghost : p.buttonBg) : \"transparent\", color: on && !out ? p.buttonText : out ? p.muted : p.title }}\n                >\n                  <span className={cn(out && \"line-through decoration-1\")}>{s.label}</span>\n                  {watching ? (\n                    <span className=\"absolute -top-1.5 -right-1.5 grid size-5 place-items-center rounded-full\" style={{ background: p.accent }} aria-hidden=\"true\">\n                      <Bell ring={0} color={p.accentText} size={11} />\n                    </span>\n                  ) : null}\n                </button>\n              );\n            })}\n          </div>\n\n          <div className=\"mt-5\">\n            <AnimatePresence mode=\"wait\" initial={false}>\n              {!soldOut ? (\n                <motion.div key=\"buy\" initial={reduce ? false : { opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: -8 }} transition={{ duration: 0.22, ease }}>\n                  <motion.button\n                    type=\"button\"\n                    onClick={() => (setAdded(cur.label), onAdd?.(cur.label))}\n                    whileTap={reduce ? undefined : { scale: 0.98 }}\n                    animate={{ background: added === cur.label ? p.accent : p.buttonBg, color: added === cur.label ? p.accentText : p.buttonText }}\n                    className=\"h-12 w-full rounded-full text-[15px] font-semibold\"\n                  >\n                    {added === cur.label ? `Added · US ${cur.label}` : `Add to cart · US ${cur.label}`}\n                  </motion.button>\n                  <p className=\"mt-3 flex items-center gap-2 text-[13px]\">\n                    <span className=\"size-2 rounded-full\" style={{ background: cur.stock <= 3 ? p.amber : p.accent }} />\n                    {cur.stock <= 3 ? `Only ${cur.stock} left in US ${cur.label}` : \"In stock · ships tomorrow\"}\n                  </p>\n                </motion.div>\n              ) : (\n                <motion.div\n                  key={`out-${cur.label}`}\n                  initial={reduce ? false : { opacity: 0, y: 8 }}\n                  animate={{ opacity: 1, y: 0 }}\n                  exit={{ opacity: 0, y: -8 }}\n                  transition={{ duration: 0.22, ease }}\n                  className=\"rounded-2xl border p-4 sm:p-5\"\n                  style={{ borderColor: p.line, background: p.card }}\n                >\n                  <AnimatePresence mode=\"wait\" initial={false}>\n                    {alert ? (\n                      <motion.div key=\"on\" initial={reduce ? false : { opacity: 0, scale: 0.97 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0 }} transition={{ duration: 0.25 }} role=\"status\">\n                        <div className=\"flex items-start gap-3\">\n                          <span className=\"grid size-10 shrink-0 place-items-center rounded-full\" style={{ background: p.accent }}>\n                            <Bell ring={ring} color={p.accentText} size={19} />\n                          </span>\n                          <div className=\"min-w-0\">\n                            <p className=\"text-[15px] font-semibold\" style={{ color: p.title }}>\n                              You’re on the list for US {alert.size}\n                            </p>\n                            <p className=\"mt-0.5 text-[13px] leading-relaxed break-words\">\n                              We’ll {alert.channel === \"email\" ? \"email\" : \"text\"} <span style={{ color: p.title }}>{alert.contact}</span> as soon as it’s back{alert.similar ? \", and if a half size either side restocks first\" : \"\"}.\n                            </p>\n                          </div>\n                        </div>\n                        <div className=\"mt-4 flex flex-wrap gap-2\">\n                          <button type=\"button\" onClick={() => cancel(alert)} className=\"rounded-full border px-4 py-2 text-[13px] font-medium\" style={{ borderColor: p.line, color: p.title }}>\n                            Cancel alert\n                          </button>\n                          {sizes\n                            .filter((s) => s.stock > 0 && Math.abs(Number(s.label) - Number(alert.size)) <= 0.5)\n                            .map((s) => (\n                              <button key={s.label} type=\"button\" onClick={() => pick(s)} className=\"rounded-full px-4 py-2 text-[13px] font-medium\" style={{ background: p.ghost, color: p.title }}>\n                                US {s.label} is in stock\n                              </button>\n                            ))}\n                        </div>\n                      </motion.div>\n                    ) : (\n                      <motion.form key=\"off\" noValidate onSubmit={subscribe} initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={{ duration: 0.2 }}>\n                        <div className=\"flex items-start gap-3\">\n                          <span className=\"grid size-10 shrink-0 place-items-center rounded-full\" style={{ background: p.ghost }}>\n                            <Bell ring={0} color={p.title} size={19} />\n                          </span>\n                          <div className=\"min-w-0\">\n                            <p className=\"text-[15px] font-semibold\" style={{ color: p.title }}>\n                              Get notified when US {cur.label} is back\n                            </p>\n                            <p className=\"mt-0.5 text-[13px]\">\n                              {cur.restock ? (\n                                <>\n                                  Expected back <span style={{ color: p.title }}>{cur.restock}</span>\n                                </>\n                              ) : (\n                                \"No restock date yet\"\n                              )}\n                              {cur.waiting ? ` · ${cur.waiting} people waiting` : \"\"}\n                            </p>\n                          </div>\n                        </div>\n\n                        <LayoutGroup id={`${uid}-ch`}>\n                          <div role=\"radiogroup\" aria-label=\"Notify me by\" className=\"mt-4 inline-flex rounded-full border p-0.5\" style={{ borderColor: p.line }}>\n                            {([\"email\", \"sms\"] as const).map((c) => {\n                              const on = channel === c;\n                              return (\n                                <button key={c} type=\"button\" role=\"radio\" aria-checked={on} onClick={() => (setChannel(c), setTried(false))} className=\"relative rounded-full px-3.5 py-1.5 text-[12px] font-medium\" style={{ color: on ? p.buttonText : p.body }}>\n                                  {on ? <motion.span layoutId=\"ch\" className=\"absolute inset-0 rounded-full\" style={{ background: p.buttonBg }} transition={{ type: \"spring\", stiffness: 500, damping: 38 }} /> : null}\n                                  <span className=\"relative\">{c === \"email\" ? \"Email\" : \"Text message\"}</span>\n                                </button>\n                              );\n                            })}\n                          </div>\n                        </LayoutGroup>\n\n                        <div className=\"mt-3 flex flex-col gap-2 sm:flex-row\">\n                          <div className=\"min-w-0 flex-1\">\n                            <label htmlFor={`${uid}-contact`} className=\"sr-only\">\n                              {channel === \"email\" ? \"Email address\" : \"Phone number\"}\n                            </label>\n                            <input\n                              ref={inputRef}\n                              id={`${uid}-contact`}\n                              type={channel === \"email\" ? \"email\" : \"tel\"}\n                              inputMode={channel === \"email\" ? \"email\" : \"tel\"}\n                              autoComplete={channel === \"email\" ? \"email\" : \"tel\"}\n                              value={channel === \"email\" ? email : phone}\n                              onChange={(e) => (channel === \"email\" ? setEmail(e.target.value) : setPhone(e.target.value))}\n                              placeholder={channel === \"email\" ? \"you@example.com\" : \"+1 555 010 2030\"}\n                              aria-invalid={!!err}\n                              aria-describedby={err ? `${uid}-err` : undefined}\n                              className={fieldCls}\n                              style={{ background: p.field, color: p.title, borderColor: err ? p.error : p.line }}\n                            />\n                          </div>\n                          <button type=\"submit\" disabled={sending} className=\"inline-flex h-11 shrink-0 items-center justify-center gap-2 rounded-full px-5 text-[14px] font-semibold disabled:opacity-80\" style={{ background: p.buttonBg, color: p.buttonText }}>\n                            {sending ? (\n                              <>\n                                <motion.span className=\"size-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                                Saving…\n                              </>\n                            ) : (\n                              \"Notify me\"\n                            )}\n                          </button>\n                        </div>\n                        <AnimatePresence initial={false}>\n                          {err ? (\n                            <motion.p id={`${uid}-err`} initial={{ opacity: 0, height: 0 }} animate={{ opacity: 1, height: \"auto\" }} exit={{ opacity: 0, height: 0 }} className=\"overflow-hidden text-[12px]\" style={{ color: p.error }}>\n                              <span className=\"block pt-1.5\">{err}</span>\n                            </motion.p>\n                          ) : null}\n                        </AnimatePresence>\n                        <label className=\"mt-3 flex cursor-pointer items-center gap-2.5 text-[13px]\">\n                          <input type=\"checkbox\" checked={similar} onChange={(e) => setSimilar(e.target.checked)} className=\"size-4\" style={{ accentColor: p.accent }} />\n                          Also tell me if a half size either side comes back first\n                        </label>\n                        <p className=\"mt-3 text-[11px]\" style={{ color: p.muted }}>\n                          One message per restock. No marketing, unsubscribe anytime.\n                        </p>\n                      </motion.form>\n                    )}\n                  </AnimatePresence>\n                </motion.div>\n              )}\n            </AnimatePresence>\n          </div>\n\n          <AnimatePresence initial={false}>\n            {alerts.length ? (\n              <motion.div key=\"alerts\" initial={{ opacity: 0, height: 0 }} animate={{ opacity: 1, height: \"auto\" }} exit={{ opacity: 0, height: 0 }} className=\"overflow-hidden\">\n                <div className=\"flex flex-wrap items-center gap-2 pt-5\">\n                  <span className=\"text-[12px]\" style={{ color: p.muted }}>\n                    Your alerts\n                  </span>\n                  <AnimatePresence initial={false} mode=\"popLayout\">\n                    {alerts.map((a) => (\n                      <motion.span\n                        key={a.size}\n                        layout={!reduce}\n                        initial={reduce ? false : { opacity: 0, scale: 0.8 }}\n                        animate={{ opacity: 1, scale: 1 }}\n                        exit={{ opacity: 0, scale: 0.8 }}\n                        className=\"inline-flex items-center gap-1.5 rounded-full py-1 pr-1 pl-2.5 text-[12px] font-medium\"\n                        style={{ background: p.accentSoft, color: p.title }}\n                      >\n                        US {a.size} · {a.channel === \"email\" ? \"Email\" : \"SMS\"}\n                        <button type=\"button\" onClick={() => cancel(a)} aria-label={`Cancel alert for US ${a.size}`} className=\"grid size-5 place-items-center rounded-full\" style={{ background: p.ghost }}>\n                          <svg width=\"8\" height=\"8\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"3.4\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                            <path d=\"M6 6l12 12M18 6 6 18\" />\n                          </svg>\n                        </button>\n                      </motion.span>\n                    ))}\n                  </AnimatePresence>\n                </div>\n              </motion.div>\n            ) : null}\n          </AnimatePresence>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default BackInStockNotify;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}