{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "product-detail",
  "title": "Product Detail",
  "description": "An eCommerce product page block with a switchable image gallery, color and size pickers, quantity stepper, animated add-to-cart button and Description / Specs / Reviews tabs.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/product-detail/product-detail.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion } 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 ProductDetailImage {\n  src: string;\n  alt?: string;\n}\n\nexport interface ProductDetailColor {\n  name: string;\n  color: string;\n}\n\nexport interface ProductDetailSpec {\n  label: string;\n  value: string;\n}\n\nexport interface ProductDetailSelection {\n  color: string | undefined;\n  size: string | undefined;\n  quantity: number;\n}\n\nexport type ProductDetailTab = \"description\" | \"specs\" | \"reviews\";\n\nexport interface ProductDetailProps {\n  /** Path segments, last one is the current page: [\"Home\", \"Shop\", \"Watches\"]. */\n  breadcrumb?: string[];\n  title: string;\n  /** 0–5. */\n  rating?: number;\n  reviewCount?: number;\n  price: string;\n  compareAtPrice?: string;\n  description?: string;\n  longDescription?: string;\n  reviewsBody?: string;\n  gallery: ProductDetailImage[];\n  colors?: ProductDetailColor[];\n  sizes?: string[];\n  specs?: ProductDetailSpec[];\n  defaultColorIndex?: number;\n  defaultSizeIndex?: number;\n  defaultTab?: ProductDetailTab;\n  buttonLabel?: string;\n  /** Small accent-colored badge next to the price, e.g. \"Free shipping\". */\n  badge?: string;\n  onAddToCart?: (selection: ProductDetailSelection) => void;\n  theme?: \"dark\" | \"light\";\n  accentColor?: string;\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)\", card: \"#161616\", buttonBg: \"#FFFFFF\", buttonText: \"#111111\", pillBorder: \"rgba(255,255,255,0.16)\", hover: \"rgba(255,255,255,0.06)\" },\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)\", card: \"#F2F2F2\", buttonBg: \"#111111\", buttonText: \"#FFFFFF\", pillBorder: \"rgba(0,0,0,0.14)\", hover: \"rgba(0,0,0,0.05)\" },\n};\n\nconst TAB_LABELS: Record<ProductDetailTab, string> = { description: \"Description\", specs: \"Specs\", reviews: \"Reviews\" };\nconst TAB_ORDER: ProductDetailTab[] = [\"description\", \"specs\", \"reviews\"];\n\nfunction Star({ filled, color }: { filled: boolean; color: string }) {\n  return (\n    <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" aria-hidden=\"true\" fill={filled ? color : \"none\"} stroke={color} strokeWidth=\"1.6\" strokeLinejoin=\"round\">\n      <path d=\"M12 3.2l2.6 5.4 5.9.8-4.3 4.1 1 5.8L12 16.5 6.8 19.3l1-5.8L3.5 9.4l5.9-.8L12 3.2z\" />\n    </svg>\n  );\n}\n\nfunction CartIcon() {\n  return (\n    <svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d=\"M3 4h2.4l2.1 10.2a1 1 0 0 0 1 .8h8.6a1 1 0 0 0 1-.8L19.5 8H6.2\" />\n      <circle cx=\"9.5\" cy=\"19\" r=\"1.2\" />\n      <circle cx=\"16.5\" cy=\"19\" r=\"1.2\" />\n    </svg>\n  );\n}\n\nfunction TruckIcon() {\n  return (\n    <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.9\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d=\"M2.5 6.5h11v9h-11zM13.5 9.5h4l3 3v3h-7\" />\n      <circle cx=\"7\" cy=\"17.5\" r=\"1.7\" />\n      <circle cx=\"17\" cy=\"17.5\" r=\"1.7\" />\n    </svg>\n  );\n}\n\nfunction CheckIcon() {\n  return (\n    <svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d=\"M5 12.5l4.5 4.5L19 7.5\" />\n    </svg>\n  );\n}\n\n// Arrow keys move between the options of a radio group and select them.\nfunction moveRadio(e: React.KeyboardEvent<HTMLElement>, index: number, count: number, select: (next: number) => void) {\n  let next = index;\n  if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") next = (index + 1) % count;\n  else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") next = (index - 1 + count) % count;\n  else return;\n  e.preventDefault();\n  select(next);\n  const radios = e.currentTarget.parentElement?.querySelectorAll<HTMLElement>('[role=\"radio\"]');\n  radios?.[next]?.focus();\n}\n\n// \"$48.00\" as a schema.org Offer; undefined when the currency symbol isn't one we recognise.\nfunction toOffer(price: string | undefined) {\n  const currency = ({ $: \"USD\", \"€\": \"EUR\", \"£\": \"GBP\", \"₺\": \"TRY\", \"¥\": \"JPY\" } as Record<string, string>)[price?.trim()[0] ?? \"\"];\n  const amount = parseFloat(price?.replace(/[^0-9.]/g, \"\") ?? \"\");\n  return currency && !Number.isNaN(amount) ? { \"@type\": \"Offer\", price: amount.toFixed(2), priceCurrency: currency } : undefined;\n}\n\nexport function ProductDetail({\n  breadcrumb,\n  title,\n  rating = 0,\n  reviewCount,\n  price,\n  compareAtPrice,\n  description,\n  longDescription,\n  reviewsBody,\n  gallery,\n  colors = [],\n  sizes = [],\n  specs = [],\n  defaultColorIndex = 0,\n  defaultSizeIndex = 0,\n  defaultTab = \"specs\",\n  buttonLabel = \"Add to Cart\",\n  badge,\n  onAddToCart,\n  theme = \"dark\",\n  accentColor = \"#F2A841\",\n  className,\n}: ProductDetailProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const [activeImage, setActiveImage] = React.useState(0);\n  const [colorIndex, setColorIndex] = React.useState(defaultColorIndex);\n  const [sizeIndex, setSizeIndex] = React.useState(defaultSizeIndex);\n  const [quantity, setQuantity] = React.useState(1);\n  const [tab, setTab] = React.useState<ProductDetailTab>(defaultTab);\n  const [added, setAdded] = React.useState(false);\n  const addedTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n\n  React.useEffect(\n    () => () => {\n      if (addedTimer.current) clearTimeout(addedTimer.current);\n    },\n    [],\n  );\n\n  const image = gallery[Math.min(activeImage, gallery.length - 1)];\n  const filledStars = Math.round(Math.max(0, Math.min(5, rating)));\n  const visibleTabs = TAB_ORDER.filter((key) => (key === \"specs\" ? specs.length > 0 : key === \"description\" ? Boolean(longDescription ?? description) : Boolean(reviewsBody)));\n  const currentTab = visibleTabs.includes(tab) ? tab : visibleTabs[0];\n\n  const handleAdd = () => {\n    onAddToCart?.({ color: colors[colorIndex]?.name, size: sizes[sizeIndex], quantity });\n    setAdded(true);\n    if (addedTimer.current) clearTimeout(addedTimer.current);\n    addedTimer.current = setTimeout(() => setAdded(false), 1800);\n  };\n\n  const ring = { [\"--tw-ring-color\" as string]: accentColor };\n  const focus = \"outline-none focus-visible:ring-2\";\n\n  // schema.org Product markup (JSON-LD) for search engines.\n  const jsonLd = JSON.stringify({\n    \"@context\": \"https://schema.org\",\n    \"@type\": \"Product\",\n    name: title,\n    ...(description ? { description } : {}),\n    image: gallery.map((g) => g.src),\n    ...(toOffer(price) ? { offers: toOffer(price) } : {}),\n    ...(rating > 0 && reviewCount ? { aggregateRating: { \"@type\": \"AggregateRating\", ratingValue: rating, reviewCount } } : {}),\n  }).replace(/</g, \"\\\\u003c\");\n\n  return (\n    <section aria-label={title} className={cn(\"@container w-full\", className)} style={{ background: p.bg, fontFamily: \"Inter, sans-serif\" }}>\n      <script type=\"application/ld+json\" dangerouslySetInnerHTML={{ __html: jsonLd }} />\n      <div className=\"mx-auto w-full max-w-[1200px] px-[18px] pt-6 pb-10 @[900px]:px-10 @[900px]:pt-8 @[900px]:pb-12\">\n        <div className=\"grid grid-cols-1 gap-[22px] @[900px]:grid-cols-2 @[900px]:gap-10\">\n          <div>\n            <div className=\"group relative mb-3 aspect-square w-full overflow-hidden rounded-2xl\" style={{ background: p.card }}>\n              <AnimatePresence mode=\"popLayout\" initial={false}>\n                {image && (\n                  <motion.img\n                    key={image.src}\n                    src={image.src}\n                    alt={image.alt ?? title}\n                    initial={{ opacity: 0 }}\n                    animate={{ opacity: 1 }}\n                    exit={{ opacity: 0 }}\n                    transition={{ duration: 0.25 }}\n                    className=\"absolute inset-0 block size-full object-cover transition-transform duration-500 ease-out group-hover:scale-[1.04]\"\n                  />\n                )}\n              </AnimatePresence>\n            </div>\n\n            {gallery.length > 1 && (\n              <div className=\"grid gap-2.5\" style={{ gridTemplateColumns: `repeat(${Math.min(gallery.length, 4)}, minmax(0, 1fr))` }}>\n                {gallery.slice(0, 4).map((item, i) => (\n                  <button\n                    key={item.src}\n                    type=\"button\"\n                    aria-label={`Show image ${i + 1} of ${gallery.length}`}\n                    aria-pressed={activeImage === i}\n                    onClick={() => setActiveImage(i)}\n                    className={cn(\"aspect-square cursor-pointer overflow-hidden rounded-[10px] p-0 transition-opacity duration-200\", focus, activeImage === i ? \"opacity-100\" : \"opacity-60 hover:opacity-100\")}\n                    style={{ background: p.card, border: `1.5px solid ${activeImage === i ? p.title : \"transparent\"}`, ...ring }}\n                  >\n                    {/* eslint-disable-next-line @next/next/no-img-element */}\n                    <img src={item.src} alt=\"\" className=\"block size-full object-cover\" />\n                  </button>\n                ))}\n              </div>\n            )}\n          </div>\n\n          <div>\n            {breadcrumb && breadcrumb.length > 0 && (\n              <nav aria-label=\"Breadcrumb\" className=\"mb-2.5 text-[13px] leading-[1.4]\" style={{ color: p.muted }}>\n                <ol className=\"m-0 flex list-none flex-wrap items-center p-0\">\n                  {breadcrumb.map((crumb, i) => (\n                    <li key={`${crumb}-${i}`} className=\"flex items-center\" aria-current={i === breadcrumb.length - 1 ? \"page\" : undefined}>\n                      {i > 0 && <span aria-hidden=\"true\" className=\"mx-1.5\">/</span>}\n                      <span>{crumb}</span>\n                    </li>\n                  ))}\n                </ol>\n              </nav>\n            )}\n\n            <h1 className=\"m-0 mb-2.5 text-[32px] leading-[1.1] font-semibold tracking-[-0.03em] @[900px]:text-[42px]\" style={{ color: p.title }}>\n              {title}\n            </h1>\n\n            <div className=\"mb-3.5 flex items-center gap-2\">\n              <span role=\"img\" aria-label={`Rated ${filledStars} out of 5`} className=\"inline-flex gap-[3px]\">\n                {[0, 1, 2, 3, 4].map((i) => (\n                  <Star key={i} filled={i < filledStars} color={p.title} />\n                ))}\n              </span>\n              {reviewCount !== undefined && (\n                <span className=\"text-[14px] leading-[1.3] font-medium\" style={{ color: p.muted }}>\n                  ({reviewCount} reviews)\n                </span>\n              )}\n            </div>\n\n            <div className=\"mb-3.5 flex flex-wrap items-center gap-x-3 gap-y-2\">\n              <span className=\"text-[32px] leading-[1.1] font-semibold\" style={{ color: p.title }}>{price}</span>\n              {compareAtPrice && <span className=\"text-[18px] leading-[1.1] line-through\" style={{ color: p.muted }}>{compareAtPrice}</span>}\n              {badge && (\n                <span\n                  className=\"inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[12px] leading-[1.2] font-medium\"\n                  style={{ color: accentColor, background: `color-mix(in srgb, ${accentColor} 14%, transparent)` }}\n                >\n                  <TruckIcon />\n                  {badge}\n                </span>\n              )}\n            </div>\n\n            {description && (\n              <p className=\"m-0 mb-5 max-w-[460px] text-[16px] leading-[1.6]\" style={{ color: p.body }}>\n                {description}\n              </p>\n            )}\n\n            {colors.length > 0 && (\n              <div className=\"mb-4\">\n                <div className=\"mb-2 text-[13px] leading-[1.3]\" style={{ color: p.muted }}>\n                  Color: <span style={{ color: p.title }}>{colors[colorIndex]?.name}</span>\n                </div>\n                <div role=\"radiogroup\" aria-label=\"Color\" className=\"flex gap-2.5\">\n                  {colors.map((item, i) => {\n                    const active = colorIndex === i;\n                    return (\n                      <button\n                        key={`${item.name}-${i}`}\n                        type=\"button\"\n                        role=\"radio\"\n                        aria-checked={active}\n                        aria-label={item.name}\n                        tabIndex={active ? 0 : -1}\n                        onClick={() => setColorIndex(i)}\n                        onKeyDown={(e) => moveRadio(e, i, colors.length, setColorIndex)}\n                        className={cn(\"size-[22px] cursor-pointer rounded-full p-0 transition-shadow duration-150\", focus)}\n                        style={{ background: item.color, border: \"2px solid transparent\", boxShadow: active ? `0 0 0 2px ${p.bg}, 0 0 0 3.5px ${p.title}` : \"none\", ...ring }}\n                      />\n                    );\n                  })}\n                </div>\n              </div>\n            )}\n\n            {sizes.length > 0 && (\n              <div className=\"mb-4\">\n                <div className=\"mb-2 text-[13px] leading-[1.3]\" style={{ color: p.muted }}>\n                  Size: <span style={{ color: p.title }}>{sizes[sizeIndex]}</span>\n                </div>\n                <div role=\"radiogroup\" aria-label=\"Size\" className=\"flex flex-wrap gap-2\">\n                  {sizes.map((label, i) => {\n                    const active = sizeIndex === i;\n                    return (\n                      <button\n                        key={label}\n                        type=\"button\"\n                        role=\"radio\"\n                        aria-checked={active}\n                        tabIndex={active ? 0 : -1}\n                        onClick={() => setSizeIndex(i)}\n                        onKeyDown={(e) => moveRadio(e, i, sizes.length, setSizeIndex)}\n                        className={cn(\"min-w-[46px] cursor-pointer rounded-full px-3 py-2 text-[14px] leading-[1.3] font-medium transition-colors duration-150\", focus, !active && \"hover:bg-[var(--pd-hover)]\")}\n                        style={{\n                          border: `1px solid ${active ? \"transparent\" : p.pillBorder}`,\n                          background: active ? p.title : \"transparent\",\n                          color: active ? p.bg : p.title,\n                          [\"--pd-hover\" as string]: p.hover,\n                          ...ring,\n                        }}\n                      >\n                        {label}\n                      </button>\n                    );\n                  })}\n                </div>\n              </div>\n            )}\n\n            <div role=\"group\" aria-label=\"Quantity\" className=\"mb-4 inline-flex items-center rounded-full\" style={{ border: `1px solid ${p.pillBorder}` }}>\n              <button\n                type=\"button\"\n                aria-label=\"Decrease quantity\"\n                disabled={quantity <= 1}\n                onClick={() => setQuantity((q) => Math.max(1, q - 1))}\n                className={cn(\"h-[38px] w-[42px] cursor-pointer rounded-full border-none bg-transparent text-[18px] leading-none transition-opacity disabled:cursor-not-allowed disabled:opacity-35\", focus)}\n                style={{ color: p.title, ...ring }}\n              >\n                &minus;\n              </button>\n              <span aria-live=\"polite\" className=\"min-w-6 text-center text-[14px] leading-[1.3] font-medium\" style={{ color: p.title }}>{quantity}</span>\n              <button\n                type=\"button\"\n                aria-label=\"Increase quantity\"\n                onClick={() => setQuantity((q) => Math.min(99, q + 1))}\n                className={cn(\"h-[38px] w-[42px] cursor-pointer rounded-full border-none bg-transparent text-[18px] leading-none\", focus)}\n                style={{ color: p.title, ...ring }}\n              >\n                +\n              </button>\n            </div>\n\n            <motion.button\n              type=\"button\"\n              onClick={handleAdd}\n              whileTap={{ scale: 0.98 }}\n              className={cn(\"flex w-full cursor-pointer items-center justify-center gap-2.5 rounded-full border-none px-[18px] py-3.5 text-[14px] leading-[1.3] font-semibold\", focus)}\n              style={{ background: p.buttonBg, color: p.buttonText, ...ring }}\n            >\n              <span aria-live=\"polite\" className=\"inline-flex items-center gap-2.5\">\n                {added ? <CheckIcon /> : <CartIcon />}\n                <span>{added ? \"Added to cart\" : buttonLabel}</span>\n              </span>\n            </motion.button>\n          </div>\n        </div>\n\n        {visibleTabs.length > 0 && (\n          <div className=\"mt-9\">\n            <div role=\"tablist\" aria-label=\"Product information\" className=\"flex gap-7\" style={{ borderBottom: `1px solid ${p.line}` }}>\n              {visibleTabs.map((key) => {\n                const active = currentTab === key;\n                return (\n                  <button\n                    key={key}\n                    type=\"button\"\n                    role=\"tab\"\n                    id={`${uid}-tab-${key}`}\n                    aria-selected={active}\n                    aria-controls={`${uid}-panel`}\n                    tabIndex={active ? 0 : -1}\n                    onClick={() => setTab(key)}\n                    onKeyDown={(e) => {\n                      const i = visibleTabs.indexOf(key);\n                      const next = e.key === \"ArrowRight\" ? (i + 1) % visibleTabs.length : e.key === \"ArrowLeft\" ? (i - 1 + visibleTabs.length) % visibleTabs.length : -1;\n                      if (next < 0) return;\n                      e.preventDefault();\n                      setTab(visibleTabs[next]);\n                      (e.currentTarget.parentElement?.querySelectorAll<HTMLElement>('[role=\"tab\"]')[next])?.focus();\n                    }}\n                    className={cn(\"relative cursor-pointer border-none bg-transparent py-2.5 text-[14px] leading-[1.3] font-medium transition-colors duration-150\", focus)}\n                    style={{ color: active ? p.title : p.muted, ...ring }}\n                  >\n                    {TAB_LABELS[key]}\n                    {active && <motion.span layoutId={`${uid}-tab-line`} className=\"absolute inset-x-0 -bottom-px h-0.5\" style={{ background: p.title }} transition={{ type: \"spring\", stiffness: 500, damping: 40 }} />}\n                  </button>\n                );\n              })}\n            </div>\n\n            <div id={`${uid}-panel`} role=\"tabpanel\" aria-labelledby={`${uid}-tab-${currentTab}`} className=\"pt-5\">\n              <AnimatePresence mode=\"wait\" initial={false}>\n                <motion.div key={currentTab} initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0 }} transition={{ duration: 0.18 }}>\n                  {currentTab === \"description\" && (\n                    <p className=\"m-0 max-w-[680px] text-[16px] leading-[1.6]\" style={{ color: p.body }}>{longDescription ?? description}</p>\n                  )}\n                  {currentTab === \"reviews\" && (\n                    <p className=\"m-0 max-w-[680px] text-[16px] leading-[1.6]\" style={{ color: p.body }}>{reviewsBody}</p>\n                  )}\n                  {currentTab === \"specs\" && (\n                    <dl className=\"m-0 grid grid-cols-1 gap-x-12 gap-y-2.5 @[900px]:grid-cols-2\">\n                      {specs.map((spec) => (\n                        <div key={spec.label} className=\"grid grid-cols-[140px_1fr] gap-4 text-[14px] leading-[1.5]\">\n                          <dt style={{ color: p.muted }}>{spec.label}</dt>\n                          <dd className=\"m-0\" style={{ color: p.title }}>{spec.value}</dd>\n                        </div>\n                      ))}\n                    </dl>\n                  )}\n                </motion.div>\n              </AnimatePresence>\n            </div>\n          </div>\n        )}\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}