{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "welcome-offer-modal",
  "title": "Welcome Offer Modal",
  "description": "A first-visit welcome modal in three steps: pick one of three welcome perks (discount, free express shipping or a free gift), enter an email, then reveal a copyable code, with a split photo layout, progress bar, and calm exits.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/welcome-offer-modal/welcome-offer-modal.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, 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 WelcomePerk {\n  id: string;\n  title: string;\n  detail: string;\n  code: string;\n  icon: \"percent\" | \"truck\" | \"gift\";\n}\n\nexport interface WelcomeOfferModalProps {\n  store?: string;\n  perks?: WelcomePerk[];\n  image?: string;\n  /** Open automatically after this many milliseconds. Set to null to wait for the button. */\n  openAfter?: number | null;\n  /** Return a Promise to keep the button busy while you subscribe the email. */\n  onClaim?: (value: { email: string; perk: string }) => void | Promise<void>;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", title: \"#FFFFFF\", muted: \"rgba(255,255,255,0.45)\", body: \"rgba(255,255,255,0.65)\", line: \"rgba(255,255,255,0.12)\", panel: \"#121212\", photo: \"#F1F1F1\", input: \"#0D0D0D\", scrim: \"rgba(0,0,0,0.6)\", buttonBg: \"#FFFFFF\", buttonText: \"#111111\", accent: \"#7CDE6A\", error: \"#FF6B57\", ring: \"rgba(255,255,255,0.5)\" },\n  light: { bg: \"#FFFFFF\", title: \"#111111\", muted: \"rgba(0,0,0,0.45)\", body: \"rgba(0,0,0,0.65)\", line: \"rgba(0,0,0,0.1)\", panel: \"#FFFFFF\", photo: \"#F1F1F1\", input: \"#FAFAF9\", scrim: \"rgba(10,10,10,0.4)\", buttonBg: \"#111111\", buttonText: \"#FFFFFF\", accent: \"#2F9E44\", error: \"#D9480F\", ring: \"rgba(0,0,0,0.45)\" },\n};\nconst PERKS: WelcomePerk[] = [\n  { id: \"percent\", title: \"15% off\", detail: \"Your first order\", code: \"HELLO15\", icon: \"percent\" },\n  { id: \"ship\", title: \"Free express\", detail: \"Shipping, any order\", code: \"HELLOSHIP\", icon: \"truck\" },\n  { id: \"gift\", title: \"Free gift\", detail: \"Notebook, orders $50+\", code: \"HELLOGIFT\", icon: \"gift\" },\n];\nconst ICON: Record<WelcomePerk[\"icon\"], string> = {\n  percent: \"M19 5 5 19M7 9a2 2 0 1 0 0-4 2 2 0 0 0 0 4zM17 19a2 2 0 1 0 0-4 2 2 0 0 0 0 4z\",\n  truck: \"M3 7h11v9H3zM14 10h4l3 3v3h-7M7 19a2 2 0 1 0 0-4 2 2 0 0 0 0 4zM17 19a2 2 0 1 0 0-4 2 2 0 0 0 0 4z\",\n  gift: \"M4 10h16v10H4zM3 7h18v3H3zM12 7v13M12 7c-2-3-6-3-6 0M12 7c2-3 6-3 6 0\",\n};\nconst GRID = [\"/demo/wireless-earbuds.webp\", \"/demo/minimal-watch.webp\", \"/demo/running-shoes.webp\", \"/demo/laptop-stand.webp\", \"/demo/notebook.webp\", \"/demo/insulated-water-bottle.webp\", \"/demo/blocks/product-list/headphones.webp\", \"/demo/blocks/product-list/backpack.webp\"];\n\nexport function WelcomeOfferModal({ store = \"Northline\", perks = PERKS, image = \"/demo/minimal-watch.webp\", openAfter = 900, onClaim, theme = \"dark\", className }: WelcomeOfferModalProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [open, setOpen] = React.useState(false);\n  const [step, setStep] = React.useState<\"pick\" | \"email\" | \"done\">(\"pick\");\n  const [perk, setPerk] = React.useState(perks[0]?.id ?? \"\");\n  const [email, setEmail] = React.useState(\"\");\n  const [error, setError] = React.useState<string | null>(null);\n  const [busy, setBusy] = React.useState(false);\n  const [copied, setCopied] = React.useState(false);\n  const triggerRef = React.useRef<HTMLButtonElement>(null);\n  const focusOnce = React.useCallback((el: HTMLElement | null) => el?.focus({ preventScroll: true }), []);\n  const chosen = perks.find((x) => x.id === perk) ?? perks[0];\n\n  React.useEffect(() => {\n    if (openAfter === null) return;\n    const t = setTimeout(() => setOpen(true), reduce ? 0 : openAfter);\n    return () => clearTimeout(t);\n  }, [openAfter, reduce]);\n  const close = React.useCallback(() => {\n    setOpen(false);\n    setTimeout(() => triggerRef.current?.focus(), 0);\n  }, []);\n  React.useEffect(() => {\n    if (!open) return;\n    const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && close();\n    window.addEventListener(\"keydown\", onKey);\n    return () => window.removeEventListener(\"keydown\", onKey);\n  }, [open, close]);\n  React.useEffect(() => {\n    if (!copied) return;\n    const t = setTimeout(() => setCopied(false), 1600);\n    return () => clearTimeout(t);\n  }, [copied]);\n\n  const claim = async (e: React.FormEvent) => {\n    e.preventDefault();\n    if (!/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email)) {\n      setError(\"Enter a valid email so we can send your code\");\n      return;\n    }\n    setError(null);\n    setBusy(true);\n    try {\n      await (onClaim ? onClaim({ email, perk }) : new Promise((r) => setTimeout(r, reduce ? 0 : 800)));\n      setStep(\"done\");\n    } finally {\n      setBusy(false);\n    }\n  };\n  const reopen = () => {\n    setStep(\"pick\");\n    setEmail(\"\");\n    setOpen(true);\n  };\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.panel } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const slide = reduce ? {} : { initial: { opacity: 0, x: 24 }, animate: { opacity: 1, x: 0 }, exit: { opacity: 0, x: -24 }, transition: { duration: 0.25, ease: [0.22, 1, 0.36, 1] as const } };\n\n  return (\n    <section className={cn(\"@container relative min-h-[620px] w-full overflow-hidden\", className)} style={{ background: p.bg, color: p.title }}>\n      {/* Store page behind */}\n      <div className=\"mx-auto max-w-6xl px-4 py-8 @[640px]:px-8\" aria-hidden={open || undefined}>\n        <div className=\"flex items-center justify-between\">\n          <span className=\"text-[17px] font-semibold\">{store}</span>\n          <button ref={triggerRef} type=\"button\" onClick={reopen} className={cn(\"h-9 cursor-pointer rounded-full border px-4 text-[12.5px] font-medium\", focus)} style={{ borderColor: p.line, background: \"transparent\", color: p.title, ...ring }}>\n            🎁 Welcome offer\n          </button>\n        </div>\n        <ul className=\"m-0 mt-6 grid list-none grid-cols-2 gap-3 p-0 @[760px]:grid-cols-4\">\n          {GRID.map((src) => (\n            <li key={src} className=\"aspect-square overflow-hidden rounded-2xl\" style={{ background: p.photo }}>\n              {/* eslint-disable-next-line @next/next/no-img-element */}\n              <img src={src} alt=\"\" className=\"h-full w-full object-cover\" />\n            </li>\n          ))}\n        </ul>\n      </div>\n\n      <AnimatePresence>\n        {open && (\n          <motion.div key=\"scrim\" className=\"absolute inset-0 z-20 flex items-start justify-center overflow-y-auto px-3 py-6 backdrop-blur-[3px]\" style={{ background: p.scrim }} initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={reduce ? undefined : { opacity: 0 }} onMouseDown={(e) => e.target === e.currentTarget && close()}>\n            <motion.div\n              role=\"dialog\"\n              aria-modal=\"true\"\n              aria-labelledby={`${uid}-t`}\n              className=\"relative my-auto grid w-full max-w-[760px] grid-cols-1 overflow-hidden rounded-3xl border shadow-[0_40px_90px_-30px_rgba(0,0,0,0.8)] @[640px]:grid-cols-[0.9fr_1.1fr]\"\n              style={{ background: p.panel, borderColor: p.line }}\n              initial={reduce ? false : { opacity: 0, y: 30, scale: 0.94 }}\n              animate={{ opacity: 1, y: 0, scale: 1 }}\n              exit={reduce ? undefined : { opacity: 0, y: 16, scale: 0.97 }}\n              transition={{ type: \"spring\", stiffness: 300, damping: 28 }}\n            >\n              <div className=\"relative hidden overflow-hidden @[640px]:block\" style={{ background: p.photo }}>\n                <motion.img src={image} alt=\"\" className=\"absolute inset-0 h-full w-full object-cover\" initial={reduce ? false : { scale: 1.15 }} animate={{ scale: 1 }} transition={{ duration: 1.2, ease: [0.22, 1, 0.36, 1] }} />\n                <motion.span className=\"absolute top-5 left-5 rounded-full bg-[#111] px-3 py-1.5 text-[12px] font-semibold text-white\" initial={reduce ? false : { opacity: 0, y: -8 }} animate={{ opacity: 1, y: 0 }} transition={{ delay: reduce ? 0 : 0.35 }}>\n                  New here? 👋\n                </motion.span>\n              </div>\n              <div className=\"relative p-6 @[640px]:p-8\">\n                <button type=\"button\" ref={focusOnce} onClick={close} aria-label=\"Close\" className={cn(\"absolute top-4 right-4 grid h-9 w-9 cursor-pointer place-items-center rounded-full border-0\", focus)} style={{ background: p.line, color: p.title, ...ring }}>\n                  <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                    <path d=\"M6 6l12 12M18 6 6 18\" />\n                  </svg>\n                </button>\n                <div className=\"flex gap-1.5 pr-12\" aria-hidden=\"true\">\n                  {[\"pick\", \"email\", \"done\"].map((s, i) => (\n                    <span key={s} className=\"h-1 flex-1 overflow-hidden rounded-full\" style={{ background: p.line }}>\n                      <motion.span className=\"block h-full rounded-full\" style={{ background: p.accent }} initial={false} animate={{ width: [\"pick\", \"email\", \"done\"].indexOf(step) >= i ? \"100%\" : \"0%\" }} transition={{ duration: reduce ? 0 : 0.4 }} />\n                    </span>\n                  ))}\n                </div>\n\n                <AnimatePresence mode=\"popLayout\" initial={false}>\n                  {step === \"pick\" && (\n                    <motion.div key=\"pick\" {...slide} className=\"mt-6\">\n                      <h2 id={`${uid}-t`} className=\"m-0 text-[26px] leading-tight font-semibold tracking-[-0.02em]\">\n                        Welcome to {store}. Pick your gift.\n                      </h2>\n                      <p className=\"m-0 mt-2 text-[14px]\" style={{ color: p.body }}>\n                        Choose one welcome perk for your first order.\n                      </p>\n                      <div role=\"radiogroup\" aria-label=\"Welcome perk\" className=\"mt-5 grid grid-cols-3 gap-2\">\n                        {perks.map((x, i) => {\n                          const on = perk === x.id;\n                          return (\n                            <motion.button\n                              key={x.id}\n                              type=\"button\"\n                              role=\"radio\"\n                              aria-checked={on}\n                              onClick={() => setPerk(x.id)}\n                              initial={reduce ? false : { opacity: 0, y: 12 }}\n                              animate={{ opacity: 1, y: 0 }}\n                              transition={{ delay: reduce ? 0 : 0.1 + i * 0.07 }}\n                              className={cn(\"relative flex cursor-pointer flex-col items-start rounded-2xl border-2 p-3 text-left\", focus)}\n                              style={{ borderColor: on ? p.accent : p.line, background: on ? `${p.accent}12` : \"transparent\", color: p.title, ...ring }}\n                            >\n                              <motion.span className=\"grid h-9 w-9 place-items-center rounded-xl\" animate={{ backgroundColor: on ? p.accent : p.line, color: on ? \"#0A0A0A\" : p.title, rotate: on && !reduce ? [0, -10, 10, 0] : 0 }} transition={{ duration: 0.4 }}>\n                                <svg width=\"17\" height=\"17\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.9\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                                  <path d={ICON[x.icon]} />\n                                </svg>\n                              </motion.span>\n                              <span className=\"mt-3 text-[14.5px] leading-tight font-semibold\">{x.title}</span>\n                              <span className=\"mt-0.5 text-[11.5px] leading-snug\" style={{ color: p.muted }}>\n                                {x.detail}\n                              </span>\n                            </motion.button>\n                          );\n                        })}\n                      </div>\n                      <button type=\"button\" onClick={() => setStep(\"email\")} className={cn(\"mt-6 flex h-12 w-full cursor-pointer items-center justify-center rounded-full border-0 text-[15px] font-semibold\", focus)} style={{ background: p.buttonBg, color: p.buttonText, ...ring }}>\n                        Claim {chosen.title.toLowerCase()} →\n                      </button>\n                      <button type=\"button\" onClick={close} className={cn(\"mt-2 h-10 w-full cursor-pointer rounded-full border-0 bg-transparent text-[13px]\", focus)} style={{ color: p.muted, ...ring }}>\n                        No thanks, I&apos;ll pay full price\n                      </button>\n                    </motion.div>\n                  )}\n                  {step === \"email\" && (\n                    <motion.form key=\"email\" {...slide} onSubmit={claim} noValidate className=\"mt-6\">\n                      <h2 id={`${uid}-t`} className=\"m-0 text-[26px] leading-tight font-semibold tracking-[-0.02em]\">\n                        Where should we send it?\n                      </h2>\n                      <p className=\"m-0 mt-2 text-[14px]\" style={{ color: p.body }}>\n                        Your {chosen.title.toLowerCase()} code lands in your inbox, plus early access to drops. Unsubscribe anytime.\n                      </p>\n                      <label htmlFor={`${uid}-email`} className=\"mt-5 block text-[12.5px] font-medium\" style={{ color: p.body }}>\n                        Email\n                      </label>\n                      <input id={`${uid}-email`} ref={focusOnce} type=\"email\" autoComplete=\"email\" value={email} onChange={(e) => {\n                          setEmail(e.target.value);\n                          setError(null);\n                        }} placeholder=\"you@example.com\" aria-invalid={!!error || undefined} aria-describedby={error ? `${uid}-err` : undefined} className=\"mt-1.5 h-12 w-full rounded-xl border px-4 text-[15px] outline-none focus-visible:ring-2\" style={{ background: p.input, borderColor: error ? p.error : p.line, color: p.title, ...ring }} />\n                      {error && (\n                        <p id={`${uid}-err`} role=\"alert\" className=\"m-0 mt-1.5 text-[12.5px]\" style={{ color: p.error }}>\n                          {error}\n                        </p>\n                      )}\n                      <button type=\"submit\" disabled={busy} className={cn(\"mt-5 flex h-12 w-full cursor-pointer items-center justify-center gap-2 rounded-full border-0 text-[15px] font-semibold disabled:opacity-80\", focus)} style={{ background: p.buttonBg, color: p.buttonText, ...ring }}>\n                        {busy ? <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.7, ease: \"linear\" }} aria-label=\"Sending\" /> : \"Send my code\"}\n                      </button>\n                      <button type=\"button\" onClick={() => setStep(\"pick\")} className={cn(\"mt-2 h-10 w-full cursor-pointer rounded-full border-0 bg-transparent text-[13px]\", focus)} style={{ color: p.muted, ...ring }}>\n                        ← Choose a different gift\n                      </button>\n                    </motion.form>\n                  )}\n                  {step === \"done\" && (\n                    <motion.div key=\"done\" {...slide} className=\"mt-6\" role=\"status\">\n                      <h2 id={`${uid}-t`} className=\"m-0 text-[26px] leading-tight font-semibold tracking-[-0.02em]\">\n                        It&apos;s yours 🎉\n                      </h2>\n                      <p className=\"m-0 mt-2 text-[14px]\" style={{ color: p.body }}>\n                        We sent it to {email}. You can also use it right now:\n                      </p>\n                      <motion.button\n                        type=\"button\"\n                        onClick={() => {\n                          navigator.clipboard?.writeText(chosen.code).catch(() => {});\n                          setCopied(true);\n                        }}\n                        className={cn(\"relative mt-5 flex w-full cursor-pointer items-center justify-between overflow-hidden rounded-2xl border-2 border-dashed px-5 py-4\", focus)}\n                        style={{ borderColor: p.accent, background: `${p.accent}12`, color: p.title, ...ring }}\n                        initial={reduce ? false : { scale: 0.9, rotate: -2 }}\n                        animate={{ scale: 1, rotate: 0 }}\n                        transition={{ type: \"spring\", stiffness: 300, damping: 14 }}\n                        aria-label={`Copy code ${chosen.code}`}\n                      >\n                        <span className=\"text-left\">\n                          <span className=\"block text-[11.5px] font-medium tracking-[0.08em] uppercase\" style={{ color: p.muted }}>\n                            {chosen.title}\n                          </span>\n                          <span className=\"mt-1 block font-mono text-[24px] font-semibold tracking-[0.12em]\">{chosen.code}</span>\n                        </span>\n                        <span className=\"text-[12.5px] font-medium\" style={{ color: copied ? p.accent : p.body }}>\n                          {copied ? \"✓ Copied\" : \"Copy\"}\n                        </span>\n                      </motion.button>\n                      <button type=\"button\" onClick={close} className={cn(\"mt-5 flex h-12 w-full cursor-pointer items-center justify-center rounded-full border-0 text-[15px] font-semibold\", focus)} style={{ background: p.buttonBg, color: p.buttonText, ...ring }}>\n                        Start shopping\n                      </button>\n                    </motion.div>\n                  )}\n                </AnimatePresence>\n              </div>\n            </motion.div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </section>\n  );\n}\n\nexport default WelcomeOfferModal;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}