{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "product-card",
  "title": "Product Card",
  "description": "Full-bleed product card with a swipeable image carousel, glass pills, rolling price and an add-to-cart button that morphs into a quantity stepper.",
  "dependencies": [
    "motion",
    "lucide-react"
  ],
  "registryDependencies": [
    "utils",
    "https://trytweenly.vercel.app/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/new-york/product-card/product-card.tsx",
      "content": "\"use client\"\n\nimport { useEffect, useState, type CSSProperties, type ReactNode } from \"react\"\nimport {\n  AnimatePresence,\n  animate,\n  motion,\n  useMotionValue,\n  useTransform,\n  type PanInfo,\n  type Transition,\n  type Variants,\n} from \"motion/react\"\nimport { Check, Heart, MapPin, Minus, Plus, ShoppingCart } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { useReducedMotion } from \"@/registry/new-york/hooks/use-reduced-motion\"\n\nexport type ProductCardBadge = string | { label: string; icon?: ReactNode }\n\nexport interface ProductCardProps {\n  /** Image URLs shown as a swipeable carousel. Missing or broken images fall back to a tinted placeholder. Default: [] */\n  images?: string[]\n  /** Product name. */\n  title: string\n  /** Short description, clamped to three lines. */\n  description?: string\n  /** Price as a number. Default: 0 */\n  price?: number\n  /** Optional price per image. The price rolls to the new value when the image changes. */\n  prices?: number[]\n  /** Currency symbol shown before the price. Default: \"₹\" */\n  currency?: string\n  /** Locale used to format numbers. Default: \"en-IN\" */\n  locale?: string\n  /** Original price, shown struck through inside the price pill. */\n  compareAt?: number\n  /** Label for the top-right pill, e.g. \"20% off\". Hidden when empty. */\n  discount?: string\n  /** Chips shown under the description. Strings or `{ label, icon }`. Default: [] */\n  badges?: ProductCardBadge[]\n  /** Location chip with a pin icon, appended after the badges. */\n  location?: string\n  /** Label of the call-to-action button. Default: \"Add to cart\" */\n  ctaLabel?: string\n  /** Called with the quantity (1) when the button is pressed. */\n  onAddToCart?: (quantity: number) => void\n  /** Controlled quantity. 0 shows the button, anything above shows the stepper. */\n  quantity?: number\n  /** Initial quantity when uncontrolled. Default: 0 */\n  defaultQuantity?: number\n  /** Called whenever the quantity changes. */\n  onQuantityChange?: (quantity: number) => void\n  /** Upper bound of the stepper. Default: 99 */\n  maxQuantity?: number\n  /** Scrim and fallback color (any CSS color). Default: \"#d9870b\" */\n  tint?: string\n  /** Button background (any CSS color). Default: \"#ffffff\" */\n  accent?: string\n  /** Button text color (any CSS color). Default: \"#0a0a0a\" */\n  accentForeground?: string\n  /** Corner radius in px. Default: 28 */\n  radius?: number\n  /** CSS aspect ratio of the card. Default: \"3 / 4.4\" */\n  aspect?: string\n  /** Advance the carousel every N ms, or false to disable. Pauses on hover. Default: false */\n  autoplay?: number | false\n  /** Show a wishlist heart in the top-left corner. Default: false */\n  wishlist?: boolean\n  /** Initial wishlist state. Default: false */\n  defaultWishlisted?: boolean\n  /** Called when the heart is toggled. */\n  onWishlistChange?: (wishlisted: boolean) => void\n  /** How images fill the card. Default: \"cover\" */\n  imageFit?: \"cover\" | \"contain\"\n  className?: string\n}\n\nconst EASE_OUT = [0.22, 1, 0.36, 1] as const\nconst SPRING: Transition = { type: \"spring\", stiffness: 450, damping: 34 }\nconst GLASS = \"border border-white/25 bg-white/[0.17] text-white backdrop-blur-md\"\n\nconst NOISE = `url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")`\n\n// Highlight position and blob rotation per slide so the fallback carousel still changes\nconst SPOTS: [number, number, number][] = [\n  [30, 22, -18],\n  [70, 26, 24],\n  [46, 16, -40],\n  [24, 34, 10],\n  [64, 20, -6],\n]\n\nconst slide: Variants = {\n  enter: (d: number) => ({ opacity: 0, scale: 1.08, x: d * 36 }),\n  center: { opacity: 1, scale: 1, x: 0 },\n  exit: (d: number) => ({ opacity: 0, scale: 1.02, x: d * -36 }),\n}\n\nconst list: Variants = {\n  hidden: {},\n  show: { transition: { staggerChildren: 0.07, delayChildren: 0.1 } },\n}\n\nconst item: Variants = {\n  hidden: { opacity: 0, y: 16, filter: \"blur(6px)\" },\n  show: { opacity: 1, y: 0, filter: \"blur(0px)\", transition: { duration: 0.6, ease: EASE_OUT } },\n}\n\nconst clamp = (v: number, min: number, max: number) => Math.min(Math.max(v, min), max)\n\nfunction Fallback({ tint, index }: { tint: string; index: number }) {\n  const [, , rot] = SPOTS[index % SPOTS.length]\n  return (\n    <div\n      aria-hidden=\"true\"\n      className=\"absolute inset-0 overflow-hidden\"\n      style={{ backgroundColor: `color-mix(in oklab, ${tint} 82%, #fff)` }}\n    >\n      <div\n        className=\"absolute left-1/2 top-[33%] aspect-[1/1.12] w-[58%] -translate-x-1/2 -translate-y-1/2\"\n        style={{\n          rotate: `${rot}deg`,\n          borderRadius: \"58% 42% 52% 48% / 62% 54% 46% 38%\",\n          backgroundColor: `color-mix(in oklab, ${tint} 55%, #fff)`,\n          boxShadow: `0 40px 60px -24px color-mix(in oklab, ${tint} 45%, #000)`,\n        }}\n      />\n      <div className=\"absolute inset-0 opacity-[0.22] mix-blend-overlay\" style={{ backgroundImage: NOISE }} />\n    </div>\n  )\n}\n\nfunction Slide({ src, alt, fit, tint, index }: { src?: string; alt: string; fit: \"cover\" | \"contain\"; tint: string; index: number }) {\n  const [state, setState] = useState<\"loading\" | \"loaded\" | \"error\">(\"loading\")\n  return (\n    <div className=\"absolute inset-0\">\n      <Fallback tint={tint} index={index} />\n      {src && state !== \"error\" && (\n        <img\n          src={src}\n          alt={alt}\n          draggable={false}\n          ref={(el) => {\n            if (el?.complete) setState(el.naturalWidth > 0 ? \"loaded\" : \"error\")\n          }}\n          onLoad={() => setState(\"loaded\")}\n          onError={() => setState(\"error\")}\n          className=\"absolute inset-0 size-full select-none transition-opacity duration-500\"\n          style={{ objectFit: fit, opacity: state === \"loaded\" ? 1 : 0 }}\n        />\n      )}\n    </div>\n  )\n}\n\nfunction Digit({ d, reduced }: { d: number; reduced: boolean }) {\n  return (\n    <span className=\"relative inline-block h-[1em] overflow-hidden leading-none\">\n      <span className=\"invisible\">0</span>\n      <motion.span\n        className=\"absolute inset-x-0 top-0 flex flex-col\"\n        initial={false}\n        animate={{ y: `${-d * 10}%` }}\n        transition={reduced ? { duration: 0 } : { type: \"spring\", stiffness: 420, damping: 34 }}\n      >\n        {Array.from({ length: 10 }, (_, n) => (\n          <span key={n} className=\"block h-[1em] leading-none\">\n            {n}\n          </span>\n        ))}\n      </motion.span>\n    </span>\n  )\n}\n\nfunction Rolling({ value, locale, reduced }: { value: number; locale: string; reduced: boolean }) {\n  const text = value.toLocaleString(locale)\n  const chars = text.split(\"\")\n  return (\n    <>\n      <span className=\"sr-only\">{text}</span>\n      <span aria-hidden=\"true\" className=\"inline-flex tabular-nums\">\n        {chars.map((c, i) => {\n          const key = chars.length - i\n          return /\\d/.test(c) ? <Digit key={key} d={Number(c)} reduced={reduced} /> : <span key={`s${key}`}>{c}</span>\n        })}\n      </span>\n    </>\n  )\n}\n\nexport function ProductCard({\n  images = [],\n  title,\n  description,\n  price = 0,\n  prices,\n  currency = \"₹\",\n  locale = \"en-IN\",\n  compareAt,\n  discount,\n  badges = [],\n  location,\n  ctaLabel = \"Add to cart\",\n  onAddToCart,\n  quantity: quantityProp,\n  defaultQuantity = 0,\n  onQuantityChange,\n  maxQuantity = 99,\n  tint = \"#d9870b\",\n  accent = \"#ffffff\",\n  accentForeground = \"#0a0a0a\",\n  radius = 28,\n  aspect = \"3 / 4.4\",\n  autoplay = false,\n  wishlist = false,\n  defaultWishlisted = false,\n  onWishlistChange,\n  imageFit = \"cover\",\n  className,\n}: ProductCardProps) {\n  const reduced = useReducedMotion()\n  const t = (tr: Transition): Transition => (reduced ? { duration: 0 } : tr)\n\n  const count = Math.max(images.length, 1)\n  const [[index, dir], setPage] = useState<[number, number]>([0, 0])\n  const [hovered, setHovered] = useState(false)\n  const [innerQty, setInnerQty] = useState(defaultQuantity)\n  const [bump, setBump] = useState(0)\n  const [liked, setLiked] = useState(defaultWishlisted)\n  const [likeTick, setLikeTick] = useState(0)\n\n  const current = index % count\n  const qty = clamp(quantityProp ?? innerQty, 0, maxQuantity)\n  const inCart = qty > 0\n  const shownPrice = prices?.[current] ?? price\n\n  const dragX = useMotionValue(0)\n  const parallax = useTransform(dragX, (v) => v * 0.22)\n\n  const goTo = (next: number, direction?: number) => {\n    const wrapped = ((next % count) + count) % count\n    if (wrapped === current) return\n    setPage([wrapped, direction ?? (wrapped > current ? 1 : -1)])\n  }\n\n  useEffect(() => {\n    if (!autoplay || count < 2 || hovered || reduced) return\n    const id = setInterval(() => setPage(([i]) => [(i + 1) % count, 1]), autoplay)\n    return () => clearInterval(id)\n  }, [autoplay, count, hovered, reduced])\n\n  const onPan = (_: PointerEvent, info: PanInfo) => {\n    if (count > 1 && !reduced) dragX.set(info.offset.x)\n  }\n\n  const onPanEnd = (_: PointerEvent, info: PanInfo) => {\n    const swipe = info.offset.x + info.velocity.x * 0.2\n    if (count > 1 && Math.abs(swipe) > 60 && Math.abs(info.offset.x) > Math.abs(info.offset.y)) {\n      goTo(current + (swipe < 0 ? 1 : -1), swipe < 0 ? 1 : -1)\n    }\n    animate(dragX, 0, t(SPRING))\n  }\n\n  const setQty = (next: number) => {\n    const v = clamp(next, 0, maxQuantity)\n    if (v === qty) return\n    if (quantityProp === undefined) setInnerQty(v)\n    if (v > qty) setBump((b) => b + 1)\n    onQuantityChange?.(v)\n  }\n\n  const addToCart = () => {\n    setQty(1)\n    onAddToCart?.(1)\n  }\n\n  const toggleLike = () => {\n    const next = !liked\n    setLiked(next)\n    if (next) setLikeTick((n) => n + 1)\n    onWishlistChange?.(next)\n  }\n\n  const chips = [\n    ...badges.map((b) => (typeof b === \"string\" ? { label: b, icon: undefined } : b)),\n    ...(location ? [{ label: location, icon: <MapPin className=\"size-3.5\" strokeWidth={2.2} /> }] : []),\n  ]\n\n  return (\n    <motion.article\n      className={cn(\n        \"@container relative isolate w-full max-w-[320px] touch-pan-y select-none overflow-hidden text-white shadow-2xl shadow-black/20\",\n        className\n      )}\n      style={{ aspectRatio: aspect, borderRadius: radius, backgroundColor: tint } as CSSProperties}\n      onHoverStart={() => setHovered(true)}\n      onHoverEnd={() => setHovered(false)}\n      onPan={onPan}\n      onPanEnd={onPanEnd}\n      aria-roledescription=\"product card\"\n      aria-label={title}\n    >\n      {/* images */}\n      <motion.div\n        className=\"absolute inset-0 -z-10\"\n        style={{ x: parallax }}\n        animate={{ scale: hovered && !reduced ? 1.06 : 1 }}\n        transition={{ duration: 1.1, ease: EASE_OUT }}\n      >\n        <AnimatePresence initial={false} custom={dir}>\n          <motion.div\n            key={current}\n            custom={dir}\n            variants={slide}\n            initial=\"enter\"\n            animate=\"center\"\n            exit=\"exit\"\n            transition={t({ duration: 0.7, ease: EASE_OUT })}\n            className=\"absolute inset-0\"\n          >\n            <Slide src={images[current]} alt={images.length > 1 ? `${title}, image ${current + 1} of ${count}` : title} fit={imageFit} tint={tint} index={current} />\n          </motion.div>\n        </AnimatePresence>\n      </motion.div>\n\n      {/* top row */}\n      <div className=\"absolute inset-x-0 top-0 flex items-start justify-between p-4\">\n        {wishlist ? (\n          <button\n            type=\"button\"\n            onClick={toggleLike}\n            aria-pressed={liked}\n            aria-label={liked ? \"Remove from wishlist\" : \"Add to wishlist\"}\n            className={cn(GLASS, \"relative grid size-9 place-items-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-white/70\")}\n          >\n            <AnimatePresence>\n              {likeTick > 0 && liked && !reduced && (\n                <motion.span\n                  key={likeTick}\n                  aria-hidden=\"true\"\n                  className=\"absolute inset-0 rounded-full border-2 border-white\"\n                  initial={{ scale: 0.6, opacity: 0.9 }}\n                  animate={{ scale: 1.7, opacity: 0 }}\n                  exit={{ opacity: 0 }}\n                  transition={{ duration: 0.5, ease: EASE_OUT }}\n                />\n              )}\n            </AnimatePresence>\n            <motion.span\n              key={likeTick}\n              className=\"grid\"\n              initial={likeTick > 0 && !reduced ? { scale: 0.6 } : false}\n              animate={{ scale: 1 }}\n              transition={{ type: \"spring\", stiffness: 500, damping: 14 }}\n            >\n              <Heart className={cn(\"size-4 transition-colors\", liked && \"fill-white\")} strokeWidth={2.2} />\n            </motion.span>\n          </button>\n        ) : (\n          <span />\n        )}\n        {discount && (\n          <motion.span\n            className={cn(GLASS, \"rounded-full px-3 py-1 text-[13px] font-medium\")}\n            initial={reduced ? false : { opacity: 0, y: -8, filter: \"blur(4px)\" }}\n            animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n            transition={{ duration: 0.6, ease: EASE_OUT, delay: 0.15 }}\n          >\n            {discount}\n          </motion.span>\n        )}\n      </div>\n\n      {/* content */}\n      <motion.div\n        className=\"absolute inset-x-0 bottom-0 flex flex-col p-[clamp(14px,6.5cqw,24px)]\"\n        // Solid tinted scrim behind the text keeps it legible over any image\n        style={{ backgroundColor: `color-mix(in oklab, ${tint} 90%, transparent)` }}\n        variants={list}\n        initial={reduced ? false : \"hidden\"}\n        whileInView=\"show\"\n        viewport={{ once: true, amount: 0.3 }}\n      >\n        {count > 1 && (\n          <motion.div variants={item} className=\"mb-3 flex items-center gap-1.5\">\n            {images.map((_, i) => (\n              <motion.button\n                key={i}\n                type=\"button\"\n                layout\n                aria-label={`Show image ${i + 1}`}\n                aria-current={i === current}\n                onClick={() => goTo(i)}\n                transition={t(SPRING)}\n                style={{ borderRadius: 999 }}\n                className={cn(\n                  \"h-1.5 outline-none transition-colors focus-visible:ring-2 focus-visible:ring-white/70\",\n                  i === current ? \"w-5 bg-white\" : \"w-1.5 bg-white/45 hover:bg-white/70\"\n                )}\n              />\n            ))}\n          </motion.div>\n        )}\n\n        <motion.div variants={item} className=\"flex items-center justify-between gap-3\">\n          <h3 className=\"min-w-0 break-words text-[clamp(22px,9.5cqw,44px)] font-bold leading-[1.05] tracking-tight [overflow-wrap:anywhere]\">{title}</h3>\n          <span className={cn(GLASS, \"flex h-9 shrink-0 items-center gap-1.5 rounded-full px-3.5 text-[17px] font-semibold leading-none\")}>\n            {compareAt !== undefined && compareAt > shownPrice && (\n              <s className=\"text-[12px] font-medium text-white/65\">\n                {currency}\n                {compareAt.toLocaleString(locale)}\n              </s>\n            )}\n            <span className=\"inline-flex items-center\">\n              {currency}\n              <Rolling value={shownPrice} locale={locale} reduced={reduced} />\n            </span>\n          </span>\n        </motion.div>\n\n        {description && (\n          <motion.p variants={item} className=\"mt-2 line-clamp-3 text-[clamp(12px,4.6cqw,15px)] leading-snug text-white/80\">\n            {description}\n          </motion.p>\n        )}\n\n        {chips.length > 0 && (\n          <motion.div variants={item} className=\"mt-3 flex flex-wrap gap-2\">\n            {chips.map((c, i) => (\n              <span key={`${c.label}-${i}`} className={cn(GLASS, \"inline-flex items-center gap-1 rounded-full px-3 py-1 text-[13px] font-medium\")}>\n                {c.icon}\n                {c.label}\n              </span>\n            ))}\n          </motion.div>\n        )}\n\n        <motion.div variants={item} className=\"relative mt-4 flex h-12 items-center justify-end\">\n          <AnimatePresence>\n            {inCart && (\n              <motion.div\n                key=\"added\"\n                className={cn(GLASS, \"absolute inset-y-0 left-0 right-[calc(136px+8px)] flex items-center justify-center gap-2 rounded-full text-sm font-medium\")}\n                initial={{ opacity: 0, x: -10, filter: \"blur(4px)\" }}\n                animate={{ opacity: 1, x: 0, filter: \"blur(0px)\" }}\n                exit={{ opacity: 0, x: -10, filter: \"blur(4px)\" }}\n                transition={t({ duration: 0.4, ease: EASE_OUT, delay: 0.08 })}\n              >\n                <motion.span\n                  key={bump}\n                  className=\"relative grid\"\n                  initial={reduced ? false : { scale: 1, rotate: 0 }}\n                  animate={reduced ? undefined : { scale: [1, 1.3, 0.92, 1], rotate: [0, -12, 6, 0] }}\n                  transition={{ duration: 0.5, ease: EASE_OUT }}\n                >\n                  <ShoppingCart className=\"size-4\" strokeWidth={2.2} />\n                  <span className=\"absolute -right-1.5 -top-1.5 grid size-3 place-items-center rounded-full bg-white\" style={{ color: tint }}>\n                    <Check className=\"size-2.5\" strokeWidth={3.5} />\n                  </span>\n                </motion.span>\n                Added\n              </motion.div>\n            )}\n          </AnimatePresence>\n\n          <motion.div\n            layout\n            transition={t(SPRING)}\n            className={cn(\"relative h-12 shrink-0 overflow-hidden\", inCart ? \"w-[136px]\" : \"w-full\")}\n            style={{ borderRadius: 999, backgroundColor: accent, color: accentForeground }}\n          >\n            <AnimatePresence initial={false}>\n              {inCart ? (\n                <motion.div\n                  key=\"stepper\"\n                  layout=\"position\"\n                  className=\"absolute inset-0 flex items-center justify-between px-1.5\"\n                  initial={{ opacity: 0, scale: 0.85 }}\n                  animate={{ opacity: 1, scale: 1 }}\n                  exit={{ opacity: 0, scale: 0.85 }}\n                  transition={t({ duration: 0.3, ease: EASE_OUT })}\n                >\n                  <button\n                    type=\"button\"\n                    aria-label=\"Decrease quantity\"\n                    onClick={() => setQty(qty - 1)}\n                    className=\"grid size-9 place-items-center rounded-full outline-none transition hover:bg-black/[0.06] focus-visible:ring-2 focus-visible:ring-black/20 active:scale-90\"\n                  >\n                    <Minus className=\"size-4\" strokeWidth={2.4} />\n                  </button>\n                  <span className=\"text-base font-semibold leading-none\" aria-live=\"polite\">\n                    <Rolling value={qty} locale={locale} reduced={reduced} />\n                  </span>\n                  <button\n                    type=\"button\"\n                    aria-label=\"Increase quantity\"\n                    disabled={qty >= maxQuantity}\n                    onClick={() => setQty(qty + 1)}\n                    className=\"grid size-9 place-items-center rounded-full outline-none transition hover:bg-black/[0.06] focus-visible:ring-2 focus-visible:ring-black/20 active:scale-90 disabled:opacity-40\"\n                  >\n                    <Plus className=\"size-4\" strokeWidth={2.4} />\n                  </button>\n                </motion.div>\n              ) : (\n                <motion.button\n                  key=\"cta\"\n                  type=\"button\"\n                  layout=\"position\"\n                  onClick={addToCart}\n                  className=\"absolute inset-0 flex items-center justify-center text-[15px] font-semibold outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-black/20\"\n                  initial={{ opacity: 0, scale: 0.9 }}\n                  animate={{ opacity: 1, scale: 1 }}\n                  exit={{ opacity: 0, scale: 0.9 }}\n                  whileTap={reduced ? undefined : { scale: 0.97 }}\n                  transition={t({ duration: 0.3, ease: EASE_OUT })}\n                >\n                  <span className=\"whitespace-nowrap\">{ctaLabel}</span>\n                </motion.button>\n              )}\n            </AnimatePresence>\n          </motion.div>\n        </motion.div>\n      </motion.div>\n    </motion.article>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs, live playground and every prop: https://trytweenly.vercel.app/docs/components/product-card",
  "type": "registry:component"
}