{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cart-offer-modal",
  "title": "Cart Offer Modal",
  "description": "An add-to-cart modal with a mix-and-match deal: it confirms the item, shows how many more to add for the next discount tier on a progress track, lets shoppers add picks right in the modal with prices already discounted, and counts the savings and total as tiers unlock.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/cart-offer-modal/cart-offer-modal.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, animate, motion, useMotionValue, useReducedMotion, useTransform } 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 OfferProduct {\n  id: string;\n  title: string;\n  price: number;\n  image?: string;\n}\n\nexport interface OfferTier {\n  items: number;\n  percent: number;\n}\n\nexport interface CartOfferModalProps {\n  added?: OfferProduct;\n  picks?: OfferProduct[];\n  tiers?: OfferTier[];\n  currency?: string;\n  onAdd?: (id: string) => void;\n  onCheckout?: (value: { items: string[]; total: number }) => 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\", well: \"rgba(255,255,255,0.04)\", photo: \"#F1F1F1\", scrim: \"rgba(0,0,0,0.6)\", buttonBg: \"#FFFFFF\", buttonText: \"#111111\", accent: \"#7CDE6A\", 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\", well: \"rgba(0,0,0,0.03)\", photo: \"#F1F1F1\", scrim: \"rgba(10,10,10,0.4)\", buttonBg: \"#111111\", buttonText: \"#FFFFFF\", accent: \"#2F9E44\", ring: \"rgba(0,0,0,0.45)\" },\n};\nconst ADDED: OfferProduct = { id: \"bottle\", title: \"Insulated Water Bottle\", price: 39, image: \"/demo/insulated-water-bottle.webp\" };\nconst PICKS: OfferProduct[] = [\n  { id: \"notebook\", title: \"Premium Notebook\", price: 24, image: \"/demo/notebook.webp\" },\n  { id: \"stand\", title: \"Laptop Stand\", price: 49, image: \"/demo/laptop-stand.webp\" },\n  { id: \"watch\", title: \"Minimal Watch\", price: 79, image: \"/demo/minimal-watch.webp\" },\n  { id: \"earbuds\", title: \"Wireless Earbuds\", price: 129, image: \"/demo/wireless-earbuds.webp\" },\n];\nconst TIERS: OfferTier[] = [\n  { items: 2, percent: 10 },\n  { items: 3, percent: 20 },\n];\n\nfunction Money({ value, currency, reduce }: { value: number; currency: string; reduce: boolean }) {\n  const mv = useMotionValue(value);\n  const text = useTransform(mv, (v) => `${currency}${v.toFixed(2)}`);\n  React.useEffect(() => {\n    if (reduce) {\n      mv.set(value);\n      return;\n    }\n    const c = animate(mv, value, { duration: 0.5, ease: [0.22, 1, 0.36, 1] });\n    return () => c.stop();\n  }, [value, reduce, mv]);\n  return <motion.span>{text}</motion.span>;\n}\n\nexport function CartOfferModal({ added = ADDED, picks = PICKS, tiers = TIERS, currency = \"$\", onAdd, onCheckout, theme = \"dark\", className }: CartOfferModalProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [open, setOpen] = React.useState(false);\n  const [extra, setExtra] = React.useState<string[]>([]);\n  const [justAdded, setJustAdded] = React.useState<string | null>(null);\n  const triggerRef = React.useRef<HTMLButtonElement>(null);\n  const focusOnce = React.useCallback((el: HTMLElement | null) => el?.focus({ preventScroll: true }), []);\n\n  const items = [added, ...picks.filter((x) => extra.includes(x.id))];\n  const count = items.length;\n  const subtotal = items.reduce((a, x) => a + x.price, 0);\n  const tier = [...tiers].reverse().find((t) => count >= t.items);\n  const next = tiers.find((t) => count < t.items);\n  const discount = tier ? subtotal * (tier.percent / 100) : 0;\n  const total = subtotal - discount;\n  const maxItems = tiers[tiers.length - 1].items;\n  const money = (n: number) => `${currency}${n.toFixed(2)}`;\n\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 (!justAdded) return;\n    const t = setTimeout(() => setJustAdded(null), 1200);\n    return () => clearTimeout(t);\n  }, [justAdded]);\n\n  const toggle = (id: string) => {\n    const on = extra.includes(id);\n    setExtra((x) => (on ? x.filter((i) => i !== id) : [...x, id]));\n    if (!on) {\n      setJustAdded(id);\n      onAdd?.(id);\n    }\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\n  return (\n    <section className={cn(\"@container relative min-h-[640px] w-full overflow-hidden\", className)} style={{ background: p.bg, color: p.title }}>\n      {/* Product page behind */}\n      <div className=\"mx-auto grid max-w-6xl grid-cols-1 items-center gap-8 px-4 py-10 @[640px]:px-8 @[760px]:grid-cols-2\" aria-hidden={open || undefined}>\n        <div className=\"aspect-square overflow-hidden rounded-3xl\" style={{ background: p.photo }}>\n          {/* eslint-disable-next-line @next/next/no-img-element */}\n          {added.image && <img src={added.image} alt=\"\" className=\"h-full w-full object-cover\" />}\n        </div>\n        <div>\n          <h2 className=\"m-0 text-[34px] font-semibold tracking-[-0.03em]\">{added.title}</h2>\n          <p className=\"m-0 mt-2 text-[22px] font-semibold tabular-nums\">{money(added.price)}</p>\n          <p className=\"m-0 mt-3 text-[14.5px]\" style={{ color: p.body }}>\n            Mix and match: buy {tiers[0].items}, save {tiers[0].percent}%. Buy {maxItems}, save {tiers[tiers.length - 1].percent}%.\n          </p>\n          <button\n            ref={triggerRef}\n            type=\"button\"\n            onClick={() => {\n              setExtra([]);\n              setOpen(true);\n            }}\n            aria-haspopup=\"dialog\"\n            className={cn(\"mt-6 flex h-12 w-full cursor-pointer items-center justify-center rounded-full border-0 text-[15px] font-semibold @[760px]:w-auto @[760px]:px-8\", focus)}\n            style={{ background: p.buttonBg, color: p.buttonText, ...ring }}\n          >\n            Add to cart\n          </button>\n        </div>\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\" 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 w-full max-w-[560px] overflow-hidden rounded-3xl border p-5 shadow-[0_40px_90px_-30px_rgba(0,0,0,0.8)] @[480px]:p-6\"\n              style={{ background: p.panel, borderColor: p.line }}\n              initial={reduce ? false : { opacity: 0, y: 40 }}\n              animate={{ opacity: 1, y: 0 }}\n              exit={reduce ? undefined : { opacity: 0, y: 24 }}\n              transition={{ type: \"spring\", stiffness: 320, damping: 30 }}\n            >\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\n              <div className=\"flex items-center gap-3 pr-12\">\n                <span className=\"relative h-12 w-12 shrink-0 overflow-hidden rounded-xl\" style={{ background: p.photo }}>\n                  {/* eslint-disable-next-line @next/next/no-img-element */}\n                  {added.image && <img src={added.image} alt=\"\" className=\"h-full w-full object-cover\" />}\n                  <motion.span className=\"absolute right-0.5 bottom-0.5 grid h-5 w-5 place-items-center rounded-full text-[11px] font-bold text-[#0A0A0A]\" style={{ background: p.accent }} initial={reduce ? false : { scale: 0 }} animate={{ scale: 1 }} transition={{ type: \"spring\", stiffness: 500, damping: 16, delay: reduce ? 0 : 0.25 }} aria-hidden=\"true\">\n                    ✓\n                  </motion.span>\n                </span>\n                <span className=\"min-w-0\">\n                  <span className=\"block text-[12px] font-medium\" style={{ color: p.accent }}>\n                    Added to your cart\n                  </span>\n                  <span className=\"block truncate text-[14px] font-medium\">{added.title}</span>\n                </span>\n              </div>\n\n              <div className=\"mt-5 rounded-2xl p-4\" style={{ background: p.well }} aria-live=\"polite\">\n                <AnimatePresence mode=\"popLayout\" initial={false}>\n                  <motion.h2 key={next ? `n${next.items}` : \"max\"} id={`${uid}-t`} className=\"m-0 text-[20px] leading-tight font-semibold tracking-[-0.01em]\" initial={reduce ? false : { opacity: 0, y: 10 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0, y: -10 }} transition={{ duration: 0.25 }}>\n                    {next ? (\n                      <>\n                        Add {next.items - count} more, save <span style={{ color: p.accent }}>{next.percent}%</span> on everything\n                      </>\n                    ) : (\n                      <>\n                        🎉 Best deal unlocked: <span style={{ color: p.accent }}>{tier?.percent}% off</span>\n                      </>\n                    )}\n                  </motion.h2>\n                </AnimatePresence>\n                <div className=\"relative mt-5 mb-7 h-7\">\n                  <span className=\"absolute inset-x-[14px] top-1/2 h-1.5 -translate-y-1/2 rounded-full\" style={{ background: p.line }} />\n                  <span className=\"absolute inset-x-[14px] top-1/2 -translate-y-1/2\">\n                    <motion.span className=\"block h-1.5 rounded-full\" style={{ background: p.accent }} initial={false} animate={{ width: `${Math.min(1, (count - 1) / (maxItems - 1)) * 100}%` }} transition={{ duration: reduce ? 0 : 0.5, ease: [0.22, 1, 0.36, 1] }} />\n                  </span>\n                  <span className=\"absolute inset-x-[14px] inset-y-0\">\n                    {Array.from({ length: maxItems }, (_, i) => {\n                      const n = i + 1;\n                      const t = tiers.find((x) => x.items === n);\n                      const on = count >= n;\n                      return (\n                        <span key={n} className=\"absolute top-0 -translate-x-1/2\" style={{ left: `${(i / (maxItems - 1)) * 100}%` }}>\n                          <motion.span className=\"relative grid h-7 w-7 place-items-center rounded-full border-2 text-[11px] font-semibold tabular-nums\" animate={{ backgroundColor: on ? p.accent : p.panel, borderColor: on ? p.accent : p.line, color: on ? \"#0A0A0A\" : p.muted, scale: on && !reduce ? [1, 1.2, 1] : 1 }} transition={{ duration: 0.35 }}>\n                            {n}\n                          </motion.span>\n                          <span className=\"absolute top-8 left-1/2 -translate-x-1/2 text-[11px] font-medium whitespace-nowrap\" style={{ color: on ? p.title : p.muted }}>\n                            {t ? `−${t.percent}%` : \"Item\"}\n                          </span>\n                        </span>\n                      );\n                    })}\n                  </span>\n                </div>\n              </div>\n\n              <p className=\"m-0 mt-5 text-[12px] font-medium tracking-[0.08em] uppercase\" style={{ color: p.muted }}>\n                Pick {next ? `${next.items - count} more` : \"more if you like\"}\n              </p>\n              <ul className=\"m-0 mt-2.5 grid list-none grid-cols-2 gap-2 p-0 @[480px]:grid-cols-4\">\n                {picks.map((x, i) => {\n                  const on = extra.includes(x.id);\n                  return (\n                    <motion.li key={x.id} initial={reduce ? false : { opacity: 0, y: 12 }} animate={{ opacity: 1, y: 0 }} transition={{ delay: reduce ? 0 : 0.15 + i * 0.05 }}>\n                      <button type=\"button\" aria-pressed={on} onClick={() => toggle(x.id)} aria-label={`${on ? \"Remove\" : \"Add\"} ${x.title}, ${money(x.price)}`} className={cn(\"group relative block w-full cursor-pointer overflow-hidden rounded-2xl border-2 p-0 text-left\", focus)} style={{ borderColor: on ? p.accent : \"transparent\", background: p.well, color: p.title, ...ring }}>\n                        <span className=\"relative block aspect-square overflow-hidden\" style={{ background: p.photo }}>\n                          {/* eslint-disable-next-line @next/next/no-img-element */}\n                          {x.image && <img src={x.image} alt=\"\" className=\"h-full w-full object-cover transition-transform duration-500 group-hover:scale-105\" />}\n                          <motion.span className=\"absolute top-2 right-2 grid h-7 w-7 place-items-center rounded-full text-[15px] leading-none font-semibold shadow\" animate={{ backgroundColor: on ? p.accent : \"#FFFFFF\", color: \"#111111\", rotate: on ? 45 : 0, scale: justAdded === x.id && !reduce ? [1, 1.3, 1] : 1 }} transition={{ duration: 0.3 }} aria-hidden=\"true\">\n                            +\n                          </motion.span>\n                        </span>\n                        <span className=\"block px-2.5 pt-2 pb-2.5\">\n                          <span className=\"block truncate text-[12.5px] font-medium\">{x.title}</span>\n                          <span className=\"block text-[12px] tabular-nums\" style={{ color: p.muted }}>\n                            {tier || next ? (\n                              <>\n                                <span style={{ color: p.title }}>{money(x.price * (1 - (tier?.percent ?? next?.percent ?? 0) / 100))}</span> <span className=\"line-through\">{money(x.price)}</span>\n                              </>\n                            ) : (\n                              money(x.price)\n                            )}\n                          </span>\n                        </span>\n                      </button>\n                    </motion.li>\n                  );\n                })}\n              </ul>\n\n              <div className=\"mt-5 flex items-end justify-between border-t pt-4\" style={{ borderColor: p.line }}>\n                <span className=\"text-[13px]\" style={{ color: p.body }}>\n                  {count} {count === 1 ? \"item\" : \"items\"}\n                  <AnimatePresence initial={false}>\n                    {discount > 0 && (\n                      <motion.span key=\"save\" className=\"block font-medium\" style={{ color: p.accent }} initial={reduce ? false : { opacity: 0, y: 4 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0 }}>\n                        You save <Money value={discount} currency={currency} reduce={reduce} />\n                      </motion.span>\n                    )}\n                  </AnimatePresence>\n                </span>\n                <span className=\"text-right\">\n                  {discount > 0 && (\n                    <span className=\"block text-[12.5px] tabular-nums line-through\" style={{ color: p.muted }}>\n                      {money(subtotal)}\n                    </span>\n                  )}\n                  <span className=\"block text-[24px] font-semibold tracking-[-0.02em] tabular-nums\">\n                    <Money value={total} currency={currency} reduce={reduce} />\n                  </span>\n                </span>\n              </div>\n              <div className=\"mt-4 grid grid-cols-1 gap-2 @[480px]:grid-cols-2\">\n                <button type=\"button\" onClick={close} className={cn(\"h-12 cursor-pointer rounded-full border bg-transparent text-[14px] font-medium\", focus)} style={{ borderColor: p.line, color: p.title, ...ring }}>\n                  Keep shopping\n                </button>\n                <button type=\"button\" onClick={() => onCheckout?.({ items: items.map((x) => x.id), total })} className={cn(\"h-12 cursor-pointer rounded-full border-0 text-[14px] font-semibold\", focus)} style={{ background: p.buttonBg, color: p.buttonText, ...ring }}>\n                  Checkout · {money(total)}\n                </button>\n              </div>\n            </motion.div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </section>\n  );\n}\n\nexport default CartOfferModal;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}