{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "related-products-block",
  "title": "Related Products Block",
  "description": "A 'You may also like' product row: tabs for similar items and complete-the-setup picks, a snap-scrolling carousel with arrow buttons and a scroll progress bar, sale and new badges, wishlist hearts, quick add on hover with a running bag count, prices and ratings.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/related-products-block/related-products-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 RelatedProduct {\n  id: string;\n  title: string;\n  price: number;\n  compareAtPrice?: number;\n  rating: number;\n  reviews: number;\n  image?: string;\n  badge?: string;\n}\n\nexport interface RelatedProductsBlockProps {\n  title?: string;\n  tabs?: { id: string; label: string; products: RelatedProduct[] }[];\n  currency?: string;\n  /** Return a Promise to keep the card button busy until the cart updates. */\n  onAddToCart?: (product: RelatedProduct) => void | Promise<void>;\n  onToggleWishlist?: (product: RelatedProduct, saved: boolean) => 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.62)\", line: \"rgba(255,255,255,0.12)\", photo: \"#F1F1F1\", buttonBg: \"#FFFFFF\", buttonText: \"#111111\", accent: \"#7CDE6A\", sale: \"#FF6B57\", track: \"rgba(255,255,255,0.12)\", 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.62)\", line: \"rgba(0,0,0,0.1)\", photo: \"#F1F1F1\", buttonBg: \"#111111\", buttonText: \"#FFFFFF\", accent: \"#2F9E44\", sale: \"#D9480F\", track: \"rgba(0,0,0,0.1)\", ring: \"rgba(0,0,0,0.45)\" },\n};\nconst P = (id: string, title: string, price: number, rating: number, reviews: number, image: string, compareAtPrice?: number, badge?: string): RelatedProduct => ({ id, title, price, rating, reviews, image, compareAtPrice, badge });\nconst TABS = [\n  {\n    id: \"similar\",\n    label: \"Similar items\",\n    products: [\n      P(\"headphones\", \"Noise Cancelling Headphones\", 199, 4.7, 1320, \"/demo/blocks/product-list/headphones.webp\", undefined, \"New\"),\n      P(\"watch\", \"Minimal Watch\", 79, 4.9, 864, \"/demo/minimal-watch.webp\", 129),\n      P(\"bottle\", \"Insulated Water Bottle\", 39, 4.8, 2210, \"/demo/insulated-water-bottle.webp\"),\n      P(\"shoes\", \"Running Shoes\", 99, 4.6, 640, \"/demo/running-shoes.webp\", 149),\n      P(\"notebook\", \"Premium Notebook\", 24, 4.8, 1980, \"/demo/notebook.webp\"),\n      P(\"backpack\", \"Everyday Backpack\", 89, 4.7, 512, \"/demo/blocks/product-list/backpack.webp\", undefined, \"New\"),\n    ],\n  },\n  {\n    id: \"setup\",\n    label: \"Complete the setup\",\n    products: [\n      P(\"stand\", \"Laptop Stand\", 49, 4.8, 1104, \"/demo/laptop-stand.webp\", 89),\n      P(\"lamp\", \"LED Desk Lamp\", 59, 4.6, 388, \"/demo/blocks/product-list/lamp.webp\"),\n      P(\"notebook\", \"Premium Notebook\", 24, 4.8, 1980, \"/demo/notebook.webp\"),\n      P(\"bottle\", \"Insulated Water Bottle\", 39, 4.8, 2210, \"/demo/insulated-water-bottle.webp\"),\n      P(\"headphones\", \"Noise Cancelling Headphones\", 199, 4.7, 1320, \"/demo/blocks/product-list/headphones.webp\"),\n    ],\n  },\n];\n\nexport function RelatedProductsBlock({ title = \"You may also like\", tabs = TABS, currency = \"$\", onAddToCart, onToggleWishlist, theme = \"dark\", className }: RelatedProductsBlockProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [tab, setTab] = React.useState(tabs[0]?.id ?? \"\");\n  const [saved, setSaved] = React.useState<Record<string, boolean>>({});\n  const [adding, setAdding] = React.useState<string | null>(null);\n  const [added, setAdded] = React.useState<Record<string, boolean>>({});\n  const [bag, setBag] = React.useState(0);\n  const [progress, setProgress] = React.useState({ start: 0, size: 1, atStart: true, atEnd: false });\n  const [broken, setBroken] = React.useState<Record<string, boolean>>({});\n  const rowRef = React.useRef<HTMLUListElement>(null);\n  const scrollAnim = React.useRef<ReturnType<typeof animate> | null>(null);\n  const products = tabs.find((t) => t.id === tab)?.products ?? [];\n\n  const measure = React.useCallback(() => {\n    const el = rowRef.current;\n    if (!el) return;\n    const max = el.scrollWidth - el.clientWidth;\n    setProgress({ start: max > 0 ? el.scrollLeft / el.scrollWidth : 0, size: el.scrollWidth ? el.clientWidth / el.scrollWidth : 1, atStart: el.scrollLeft <= 2, atEnd: el.scrollLeft >= max - 2 });\n  }, []);\n  React.useEffect(() => {\n    const el = rowRef.current;\n    if (!el) return;\n    el.scrollLeft = 0;\n    const ro = new ResizeObserver(measure);\n    ro.observe(el);\n    const t = setTimeout(measure, 0);\n    return () => {\n      ro.disconnect();\n      clearTimeout(t);\n    };\n  }, [tab, measure]);\n\n  const scroll = (dir: 1 | -1) => {\n    const el = rowRef.current;\n    if (!el) return;\n    const card = el.querySelector(\"li\");\n    const step = card ? card.getBoundingClientRect().width + 16 : el.clientWidth * 0.8;\n    const target = Math.max(0, Math.min(el.scrollWidth - el.clientWidth, el.scrollLeft + dir * step * (el.clientWidth > 700 ? 2 : 1)));\n    scrollAnim.current?.stop();\n    if (reduce) el.scrollLeft = target;\n    else scrollAnim.current = animate(el.scrollLeft, target, { duration: 0.5, ease: [0.22, 1, 0.36, 1], onUpdate: (v) => (el.scrollLeft = v) });\n  };\n  const add = async (prod: RelatedProduct) => {\n    if (adding) return;\n    setAdding(prod.id);\n    try {\n      await (onAddToCart ? onAddToCart(prod) : new Promise((r) => setTimeout(r, reduce ? 0 : 600)));\n      setAdded((a) => ({ ...a, [prod.id]: true }));\n      setBag((b) => b + 1);\n    } finally {\n      setAdding(null);\n    }\n  };\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.bg } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const money = (n: number) => `${currency}${n.toFixed(2)}`;\n  const arrow = (dir: 1 | -1, disabled: boolean) => (\n    <button type=\"button\" onClick={() => scroll(dir)} disabled={disabled} aria-label={dir < 0 ? \"Previous products\" : \"Next products\"} className={cn(\"grid h-10 w-10 cursor-pointer place-items-center rounded-full border bg-transparent transition-opacity disabled:cursor-default disabled:opacity-30\", focus)} style={{ borderColor: p.line, color: p.title, ...ring }}>\n      <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n        <path d={dir < 0 ? \"M15 18 9 12l6-6\" : \"m9 18 6-6-6-6\"} />\n      </svg>\n    </button>\n  );\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.title }} aria-labelledby={`${uid}-title`}>\n      <div className=\"mx-auto max-w-6xl px-4 py-12 @[640px]:px-8\">\n        <div className=\"flex flex-wrap items-end justify-between gap-4\">\n          <div>\n            <h2 id={`${uid}-title`} className=\"m-0 text-[28px] font-semibold tracking-[-0.03em] @[640px]:text-[34px]\">\n              {title}\n            </h2>\n            <div role=\"tablist\" aria-label=\"Recommendation type\" className=\"mt-3 flex gap-1\">\n              {tabs.map((t) => (\n                <button key={t.id} type=\"button\" role=\"tab\" aria-selected={tab === t.id} onClick={() => setTab(t.id)} className={cn(\"relative h-8 cursor-pointer rounded-full border-0 bg-transparent px-3.5 text-[13px] font-medium\", focus)} style={{ color: tab === t.id ? p.buttonText : p.body, ...ring }}>\n                  {tab === t.id && <motion.span layoutId={reduce ? undefined : `${uid}-tab`} className=\"absolute inset-0 rounded-full\" style={{ background: p.buttonBg }} transition={{ type: \"spring\", stiffness: 500, damping: 38 }} />}\n                  <span className=\"relative\">{t.label}</span>\n                </button>\n              ))}\n            </div>\n          </div>\n          <div className=\"flex items-center gap-3\">\n            <AnimatePresence initial={false}>\n              {bag > 0 && (\n                <motion.span key=\"bag\" initial={reduce ? false : { opacity: 0, scale: 0.8 }} animate={{ opacity: 1, scale: 1 }} className=\"flex items-center gap-1.5 rounded-full px-3 py-1.5 text-[12.5px] font-medium\" style={{ background: `${p.accent}22`, color: p.accent }} aria-live=\"polite\">\n                  <motion.span key={bag} initial={reduce ? false : { scale: 1.6 }} animate={{ scale: 1 }}>\n                    {bag}\n                  </motion.span>{\" \"}\n                  in your bag\n                </motion.span>\n              )}\n            </AnimatePresence>\n            <div className=\"hidden gap-2 @[560px]:flex\">\n              {arrow(-1, progress.atStart)}\n              {arrow(1, progress.atEnd)}\n            </div>\n          </div>\n        </div>\n\n        <ul ref={rowRef} onScroll={measure} className=\"m-0 mt-6 -mx-4 flex snap-x snap-mandatory list-none gap-4 overflow-x-auto scroll-px-4 px-4 pb-2 [scrollbar-width:none] @[640px]:-mx-8 @[640px]:scroll-px-8 @[640px]:px-8 [&::-webkit-scrollbar]:hidden\" aria-label={tabs.find((t) => t.id === tab)?.label}>\n          {products.map((prod, i) => {\n            const isSaved = !!saved[prod.id];\n            const isAdded = !!added[prod.id];\n            return (\n              <motion.li key={`${tab}-${prod.id}`} className=\"group w-[72%] shrink-0 snap-start @[480px]:w-[44%] @[760px]:w-[calc((100%-3rem)/4)]\" initial={reduce ? false : { opacity: 0, y: 14 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.4, delay: reduce ? 0 : i * 0.05, ease: [0.22, 1, 0.36, 1] }}>\n                <div className=\"relative aspect-square overflow-hidden rounded-2xl\" style={{ background: p.photo }}>\n                  {prod.image && !broken[prod.id] ? (\n                    // eslint-disable-next-line @next/next/no-img-element\n                    <img src={prod.image} alt={prod.title} onError={() => setBroken((b) => ({ ...b, [prod.id]: true }))} className=\"h-full w-full object-cover transition-transform duration-500 ease-out group-hover:scale-105\" />\n                  ) : (\n                    <span className=\"grid h-full w-full place-items-center text-[48px] font-semibold text-black/15\">{prod.title[0]}</span>\n                  )}\n                  {(prod.badge || prod.compareAtPrice) && (\n                    <span className=\"absolute top-3 left-3 rounded-full px-2.5 py-1 text-[11px] font-semibold\" style={{ background: prod.compareAtPrice ? p.sale : \"#111111\", color: \"#FFFFFF\" }}>\n                      {prod.compareAtPrice ? `−${Math.round((1 - prod.price / prod.compareAtPrice) * 100)}%` : prod.badge}\n                    </span>\n                  )}\n                  <button\n                    type=\"button\"\n                    onClick={() => {\n                      setSaved((s) => ({ ...s, [prod.id]: !isSaved }));\n                      onToggleWishlist?.(prod, !isSaved);\n                    }}\n                    aria-pressed={isSaved}\n                    aria-label={`${isSaved ? \"Remove\" : \"Save\"} ${prod.title} ${isSaved ? \"from\" : \"to\"} wishlist`}\n                    className={cn(\"absolute top-3 right-3 grid h-9 w-9 cursor-pointer place-items-center rounded-full border-0 bg-white/90 shadow-sm\", focus)}\n                    style={ring}\n                  >\n                    <motion.svg key={String(isSaved)} width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill={isSaved ? \"#E5484D\" : \"none\"} stroke={isSaved ? \"#E5484D\" : \"#111\"} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" initial={reduce || !isSaved ? false : { scale: 0.4 }} animate={{ scale: 1 }} transition={{ type: \"spring\", stiffness: 500, damping: 14 }} aria-hidden=\"true\">\n                      <path d=\"M12 20s-7-4.4-7-10a4 4 0 0 1 7-2.6A4 4 0 0 1 19 10c0 5.6-7 10-7 10z\" />\n                    </motion.svg>\n                  </button>\n                  <button\n                    type=\"button\"\n                    onClick={() => add(prod)}\n                    disabled={adding === prod.id}\n                    className={cn(\"absolute right-3 bottom-3 left-3 flex h-10 cursor-pointer items-center justify-center gap-2 rounded-full border-0 text-[13px] font-semibold shadow-lg transition-all duration-300 @[760px]:translate-y-3 @[760px]:opacity-0 @[760px]:group-focus-within:translate-y-0 @[760px]:group-focus-within:opacity-100 @[760px]:group-hover:translate-y-0 @[760px]:group-hover:opacity-100\", focus)}\n                    style={{ background: isAdded ? p.accent : \"#111111\", color: isAdded ? \"#0A0A0A\" : \"#FFFFFF\", ...ring }}\n                  >\n                    {adding === prod.id ? (\n                      <motion.span className=\"h-3.5 w-3.5 rounded-full border-2 border-current border-t-transparent\" animate={reduce ? undefined : { rotate: 360 }} transition={{ repeat: Infinity, duration: 0.7, ease: \"linear\" }} aria-label=\"Adding\" />\n                    ) : isAdded ? (\n                      \"✓ Added · add another\"\n                    ) : (\n                      \"Quick add\"\n                    )}\n                  </button>\n                </div>\n                <div className=\"mt-3 flex items-start justify-between gap-3\">\n                  <a href=\"#\" className=\"min-w-0 text-[14px] font-medium no-underline outline-none hover:underline focus-visible:underline\" style={{ color: p.title }}>\n                    {prod.title}\n                  </a>\n                  <span className=\"shrink-0 text-right\">\n                    <span className=\"block text-[14px] font-semibold tabular-nums\">{money(prod.price)}</span>\n                    {prod.compareAtPrice && (\n                      <span className=\"block text-[12px] tabular-nums line-through\" style={{ color: p.muted }}>\n                        {money(prod.compareAtPrice)}\n                      </span>\n                    )}\n                  </span>\n                </div>\n                <p className=\"m-0 mt-1 flex items-center gap-1 text-[12px]\" style={{ color: p.muted }}>\n                  <svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill={p.title} aria-hidden=\"true\">\n                    <path d=\"m12 3 2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.5 2.9 1-6.1L3.2 9.5l6.1-.9z\" />\n                  </svg>\n                  <span style={{ color: p.title }}>{prod.rating.toFixed(1)}</span> ({prod.reviews.toLocaleString(\"en-US\")})\n                </p>\n              </motion.li>\n            );\n          })}\n        </ul>\n\n        <div className=\"mt-4 h-0.5 overflow-hidden rounded-full\" style={{ background: p.track }} aria-hidden=\"true\">\n          <motion.div className=\"h-full rounded-full\" style={{ background: p.title }} animate={{ width: `${progress.size * 100}%`, marginLeft: `${progress.start * 100}%` }} transition={{ duration: 0.12 }} />\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default RelatedProductsBlock;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}