{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "product-detail",
  "title": "Product Detail",
  "description": "Gallery, options, availability, price, delivery, and purchase actions.",
  "dependencies": [
    "class-variance-authority",
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "https://uaiblocks.dev/r/uai-theme.json",
    "https://uaiblocks.dev/r/product-gallery.json",
    "https://uaiblocks.dev/r/quantity-picker.json",
    "https://uaiblocks.dev/r/uai-utils.json"
  ],
  "files": [
    {
      "path": "src/registry/uai/blocks/product-detail.tsx",
      "content": "\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { Check, LoaderCircle } from \"lucide-react\";\nimport {\n  type ComponentProps,\n  createContext,\n  type FormEvent,\n  type ReactNode,\n  useContext,\n  useEffect,\n  useId,\n  useState,\n} from \"react\";\nimport { Button } from \"@/components/ui/button\";\nimport {\n  ProductGallery,\n  type ProductGalleryProps,\n  type ProductGalleryVariant,\n} from \"@/components/ui/uai/product-gallery\";\nimport {\n  QuantityPicker,\n  type QuantityPickerProps,\n  type QuantityPickerVariant,\n} from \"@/components/ui/uai/quantity-picker\";\nimport { cn } from \"@/lib/uai-utils\";\n\nexport const PRODUCT_DETAIL_VARIANTS = [\"split\", \"stacked\", \"compact\"] as const;\nexport type ProductDetailVariant = (typeof PRODUCT_DETAIL_VARIANTS)[number];\nexport type ProductDetailAvailabilityTone = \"available\" | \"low\" | \"unavailable\";\nexport type ProductDetailProps = ComponentProps<\"section\"> & {\n  variant?: ProductDetailVariant;\n  /**\n   * Called with the purchase form data (selected options and quantity) when the shopper adds\n   * the product. Return a promise to keep the action pending until the cart confirms.\n   */\n  onAddToCart?: (data: FormData) => void | Promise<void>;\n};\n\ntype DetailContext = {\n  id: string;\n  variant: ProductDetailVariant;\n  pending: boolean;\n  added: boolean;\n  submit: (event: FormEvent<HTMLFormElement>) => void;\n};\nconst Context = createContext<DetailContext | null>(null);\nfunction useDetail(part: string) {\n  const context = useContext(Context);\n  if (!context) throw new Error(`${part} must be used within ProductDetail`);\n  return context;\n}\ntype OptionContext = { name: string; legendId: string };\nconst OptionContext = createContext<OptionContext | null>(null);\nfunction useOption(part: string) {\n  const context = useContext(OptionContext);\n  if (!context) throw new Error(`${part} must be used within ProductDetailOption`);\n  return context;\n}\n\nconst galleryVariants: Record<ProductDetailVariant, ProductGalleryVariant> = {\n  split: \"side\",\n  stacked: \"stacked\",\n  compact: \"compact\",\n};\nconst quantityVariants: Record<ProductDetailVariant, QuantityPickerVariant> = {\n  split: \"rounded\",\n  stacked: \"pill\",\n  compact: \"compact\",\n};\nconst toneDot: Record<ProductDetailAvailabilityTone, string> = {\n  available: \"bg-success ring-success/18\",\n  low: \"bg-warning ring-warning/18\",\n  unavailable: \"bg-destructive ring-destructive/18\",\n};\nconst buttonClass =\n  \"rounded-full border-0 py-0 text-[13px] transition-[filter,background-color,scale] duration-[120ms,120ms,140ms] ease-[ease-out,ease-out,cubic-bezier(0.23,1,0.32,1)] focus-visible:ring-0 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring enabled:active:scale-[0.97] motion-reduce:transition-none motion-reduce:enabled:active:scale-100\";\n\nconst productDetailVariants = cva(\n  \"@container box-border min-w-0 text-[13px]/[18px] text-foreground\",\n  {\n    variants: {\n      variant: {\n        split: \"\",\n        stacked: \"mx-auto my-0 max-w-[640px]\",\n        compact: \"\",\n      },\n    },\n  },\n);\nconst layoutVariants = cva(\"grid min-w-0 items-start\", {\n  variants: {\n    variant: {\n      split: \"gap-6 @min-[720px]:grid-cols-[minmax(0,1.15fr)_minmax(0,1fr)] @min-[720px]:gap-x-10\",\n      stacked: \"gap-6\",\n      compact: \"gap-4 @min-[560px]:grid-cols-[minmax(0,0.9fr)_minmax(0,1fr)] @min-[560px]:gap-x-5\",\n    },\n  },\n});\n\n/** Gallery, options, availability, price, delivery, and purchase actions for one product. */\nexport function ProductDetail({\n  variant = \"split\",\n  onAddToCart,\n  children,\n  className,\n  ...props\n}: ProductDetailProps) {\n  const id = useId();\n  const [pending, setPending] = useState(false);\n  const [added, setAdded] = useState(false);\n  useEffect(() => {\n    if (!added) return;\n    const timer = window.setTimeout(() => setAdded(false), 1400);\n    return () => window.clearTimeout(timer);\n  }, [added]);\n  const submit = (event: FormEvent<HTMLFormElement>) => {\n    event.preventDefault();\n    if (pending) return;\n    const result = onAddToCart?.(new FormData(event.currentTarget));\n    if (!result) return;\n    setPending(true);\n    setAdded(false);\n    result.then(\n      () => {\n        setPending(false);\n        setAdded(true);\n      },\n      () => setPending(false),\n    );\n  };\n  return (\n    <Context.Provider value={{ id, variant, pending, added, submit }}>\n      <section\n        aria-labelledby={`${id}-title`}\n        data-slot=\"product-detail\"\n        data-variant={variant}\n        className={cn(productDetailVariants({ variant }), className)}\n        {...props}\n      >\n        <div className={layoutVariants({ variant })}>{children}</div>\n      </section>\n    </Context.Provider>\n  );\n}\n\n/** Product media. Compose ProductGallery parts inside; the block picks the gallery layout. */\nexport function ProductDetailGallery({\n  \"aria-label\": ariaLabel = \"Product images\",\n  ...props\n}: Omit<ProductGalleryProps, \"variant\">) {\n  const { variant } = useDetail(\"ProductDetailGallery\");\n  return (\n    <ProductGallery\n      role=\"group\"\n      aria-label={ariaLabel}\n      data-slot=\"product-detail-gallery\"\n      {...props}\n      variant={galleryVariants[variant]}\n    />\n  );\n}\n\nexport function ProductDetailInfo({ className, ...props }: ComponentProps<\"div\">) {\n  const { variant } = useDetail(\"ProductDetailInfo\");\n  return (\n    <div\n      data-slot=\"product-detail-info\"\n      className={cn(\"grid min-w-0\", variant === \"compact\" ? \"gap-3.5\" : \"gap-5\", className)}\n      {...props}\n    />\n  );\n}\n\nexport function ProductDetailHeader({ className, ...props }: ComponentProps<\"header\">) {\n  return (\n    <header\n      data-slot=\"product-detail-header\"\n      className={cn(\"grid min-w-0 gap-1.5\", className)}\n      {...props}\n    />\n  );\n}\n\nexport function ProductDetailEyebrow({ className, ...props }: ComponentProps<\"p\">) {\n  return (\n    <p\n      data-slot=\"product-detail-eyebrow\"\n      className={cn(\"m-0 text-xs/4 text-subtle-foreground\", className)}\n      {...props}\n    />\n  );\n}\n\nexport function ProductDetailTitle({ className, ...props }: ComponentProps<\"h2\">) {\n  const { id, variant } = useDetail(\"ProductDetailTitle\");\n  return (\n    <h2\n      data-slot=\"product-detail-title\"\n      className={cn(\n        \"m-0 font-semibold tracking-[-0.015em] text-balance\",\n        variant === \"compact\"\n          ? \"text-[18px]/[1.2]\"\n          : \"text-[length:clamp(20px,2cqi_+_12px,26px)]/[1.2]\",\n        className,\n      )}\n      {...props}\n      id={`${id}-title`}\n    />\n  );\n}\n\n/** Current price, with an optional compare-at price inside ProductDetailComparePrice. */\nexport function ProductDetailPrice({ className, ...props }: ComponentProps<\"p\">) {\n  const { variant } = useDetail(\"ProductDetailPrice\");\n  return (\n    <p\n      data-slot=\"product-detail-price\"\n      className={cn(\n        \"m-0 flex flex-wrap items-baseline gap-2 font-medium tabular-nums\",\n        variant === \"compact\" ? \"text-[16px]/[1.2]\" : \"text-[20px]/[1.2]\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport function ProductDetailComparePrice({ children, className, ...props }: ComponentProps<\"s\">) {\n  return (\n    <s\n      data-slot=\"product-detail-compare-price\"\n      className={cn(\"text-[13px] font-normal text-subtle-foreground\", className)}\n      {...props}\n    >\n      <span className=\"sr-only\">Was </span>\n      {children}\n    </s>\n  );\n}\n\nexport function ProductDetailDescription({ className, ...props }: ComponentProps<\"p\">) {\n  return (\n    <p\n      data-slot=\"product-detail-description\"\n      className={cn(\"m-0 text-pretty text-muted-foreground\", className)}\n      {...props}\n    />\n  );\n}\n\n/** The purchase form. Options and quantity inside it are submitted to onAddToCart. */\nexport function ProductDetailPurchase({ className, onSubmit, ...props }: ComponentProps<\"form\">) {\n  const context = useDetail(\"ProductDetailPurchase\");\n  return (\n    <form\n      data-slot=\"product-detail-purchase\"\n      className={cn(\"grid min-w-0\", context.variant === \"compact\" ? \"gap-3\" : \"gap-4\", className)}\n      {...props}\n      aria-busy={context.pending || undefined}\n      onSubmit={(event) => {\n        onSubmit?.(event);\n        if (!event.defaultPrevented) context.submit(event);\n        else event.preventDefault();\n      }}\n    />\n  );\n}\n\nexport type ProductDetailOptionProps = Omit<ComponentProps<\"fieldset\">, \"onChange\"> & {\n  /** Form field name submitted with the purchase. */\n  name: string;\n  /** The visible legend, for example \"Color\". */\n  label: ReactNode;\n  /** Optional current selection text shown beside the legend. */\n  selection?: ReactNode;\n  onValueChange?: (value: string) => void;\n};\n\n/** A required radio group for one product option, such as color or size. */\nexport function ProductDetailOption({\n  name,\n  label,\n  selection,\n  onValueChange,\n  children,\n  className,\n  ...props\n}: ProductDetailOptionProps) {\n  useDetail(\"ProductDetailOption\");\n  const legendId = useId();\n  return (\n    <OptionContext.Provider value={{ name, legendId }}>\n      <fieldset\n        data-slot=\"product-detail-option\"\n        className={cn(\"m-0 grid min-w-0 gap-2 border-0 p-0\", className)}\n        {...props}\n        onChange={(event) => {\n          const target = event.target;\n          if (target instanceof HTMLInputElement && target.name === name) {\n            onValueChange?.(target.value);\n          }\n        }}\n      >\n        <legend id={legendId} className=\"mb-1.5 flex gap-1.5 p-0 font-medium\">\n          {label}\n          {selection ? (\n            <span className=\"font-normal text-subtle-foreground\">{selection}</span>\n          ) : null}\n        </legend>\n        <div className=\"flex flex-wrap gap-2\">{children}</div>\n      </fieldset>\n    </OptionContext.Provider>\n  );\n}\n\nexport type ProductDetailOptionValueProps = Omit<\n  ComponentProps<\"input\">,\n  \"type\" | \"name\" | \"value\" | \"children\"\n> & {\n  value: string;\n  children: ReactNode;\n  /** Optional swatch color shown before the label. */\n  swatch?: string;\n};\n\n/** One choice inside ProductDetailOption. Disable sold-out values instead of hiding them. */\nexport function ProductDetailOptionValue({\n  value,\n  swatch,\n  children,\n  className,\n  ...props\n}: ProductDetailOptionValueProps) {\n  const option = useOption(\"ProductDetailOptionValue\");\n  return (\n    <label\n      data-slot=\"product-detail-option-value\"\n      className={cn(\n        \"relative inline-flex min-h-8 cursor-pointer items-center gap-2 rounded-full bg-secondary text-[13px] font-medium text-muted-foreground\",\n        \"transition-[background-color,box-shadow,color,scale] duration-[120ms,120ms,120ms,140ms] ease-[ease-out,ease-out,ease-out,cubic-bezier(0.23,1,0.32,1)] hover:bg-[color-mix(in_oklab,var(--secondary)_85%,var(--foreground))] active:scale-[0.97] has-[input:disabled]:active:scale-100 motion-reduce:transition-none motion-reduce:active:scale-100\",\n        \"has-[input:focus-visible]:outline-2 has-[input:focus-visible]:outline-offset-2 has-[input:focus-visible]:outline-ring\",\n        \"has-[input:checked]:bg-card has-[input:checked]:text-foreground has-[input:checked]:shadow-[inset_0_0_0_1.5px_var(--foreground)]\",\n        \"has-[input:disabled]:cursor-not-allowed has-[input:disabled]:bg-secondary has-[input:disabled]:line-through has-[input:disabled]:opacity-45\",\n        swatch ? \"py-0 pr-3 pl-1.5\" : \"px-3 py-0\",\n        className,\n      )}\n    >\n      <input\n        {...props}\n        type=\"radio\"\n        name={option.name}\n        value={value}\n        required\n        className=\"absolute inset-0 m-0 cursor-[inherit] opacity-0\"\n      />\n      {swatch ? (\n        <span\n          aria-hidden=\"true\"\n          className=\"size-5 rounded-full shadow-[0_0_0_1px_oklch(1_0_0/0.08),inset_0_0_0_1px_oklch(0_0_0/0.12)]\"\n          style={{ background: swatch }}\n        />\n      ) : null}\n      {children}\n    </label>\n  );\n}\n\nexport type ProductDetailAvailabilityProps = ComponentProps<\"p\"> & {\n  tone?: ProductDetailAvailabilityTone;\n};\n\n/** Stock status as text with a colored dot; the text carries the meaning. */\nexport function ProductDetailAvailability({\n  tone = \"available\",\n  children,\n  className,\n  ...props\n}: ProductDetailAvailabilityProps) {\n  return (\n    <p\n      role=\"status\"\n      data-slot=\"product-detail-availability\"\n      className={cn(\"m-0 flex items-center gap-2\", className)}\n      {...props}\n      data-tone={tone}\n    >\n      <span\n        aria-hidden=\"true\"\n        className={cn(\"size-2 flex-none rounded-full ring-3\", toneDot[tone])}\n      />\n      <span className=\"font-medium text-muted-foreground\">{children}</span>\n    </p>\n  );\n}\n\n/** Quantity control for the purchase form. Compose QuantityPicker parts inside. */\nexport function ProductDetailQuantity(props: Omit<QuantityPickerProps, \"variant\">) {\n  const { variant } = useDetail(\"ProductDetailQuantity\");\n  return (\n    <QuantityPicker\n      data-slot=\"product-detail-quantity\"\n      {...props}\n      variant={quantityVariants[variant]}\n    />\n  );\n}\n\nexport function ProductDetailActions({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"product-detail-actions\"\n      className={cn(\"flex flex-wrap items-end gap-2\", className)}\n      {...props}\n    />\n  );\n}\n\nexport type ProductDetailAddToCartProps = ComponentProps<\"button\"> & {\n  /** Label while onAddToCart is pending. */\n  pendingLabel?: ReactNode;\n  /** Label shown briefly after onAddToCart resolves. */\n  addedLabel?: ReactNode;\n};\n\n/** Submits the purchase form as the block's single accent-filled action. */\nexport function ProductDetailAddToCart({\n  pendingLabel = \"Adding…\",\n  addedLabel = \"Added\",\n  children = \"Add to cart\",\n  disabled,\n  className,\n  ...props\n}: ProductDetailAddToCartProps) {\n  const context = useDetail(\"ProductDetailAddToCart\");\n  const blocked = disabled || context.pending;\n  const state = context.pending ? \"pending\" : context.added ? \"added\" : \"idle\";\n  return (\n    <Button\n      data-slot=\"product-detail-add-to-cart\"\n      variant=\"default\"\n      className={cn(\n        buttonClass,\n        \"flex-[1_1_160px] gap-2 px-4.5 text-primary-foreground has-[>svg]:px-4.5 disabled:opacity-100\",\n        context.variant === \"compact\" ? \"h-8\" : \"h-10\",\n        blocked\n          ? \"cursor-not-allowed bg-[color-mix(in_oklab,var(--primary)_55%,var(--card))] hover:bg-[color-mix(in_oklab,var(--primary)_55%,var(--card))]\"\n          : \"cursor-pointer bg-primary hover:bg-primary enabled:hover:brightness-108\",\n        className,\n      )}\n      {...props}\n      type=\"submit\"\n      disabled={blocked}\n      aria-busy={context.pending || undefined}\n      data-kind=\"primary\"\n    >\n      {context.pending ? (\n        <LoaderCircle\n          size={14}\n          aria-hidden=\"true\"\n          className=\"size-3.5 animate-[spin_900ms_linear_infinite] motion-reduce:animate-none\"\n        />\n      ) : context.added ? (\n        <Check\n          size={14}\n          aria-hidden=\"true\"\n          className=\"size-3.5 animate-in duration-200 ease-out-quint fade-in-0 zoom-in-50 motion-reduce:animate-none\"\n        />\n      ) : null}\n      {/* Labels share one cell, so the button keeps its width as the state changes. */}\n      <span className=\"grid [&>*]:[grid-area:1/1]\">\n        <span className={cn(state !== \"idle\" && \"invisible\")} aria-hidden={state !== \"idle\"}>\n          {children}\n        </span>\n        <span className={cn(state !== \"pending\" && \"invisible\")} aria-hidden={state !== \"pending\"}>\n          {pendingLabel}\n        </span>\n        <span className={cn(state !== \"added\" && \"invisible\")} aria-hidden={state !== \"added\"}>\n          {addedLabel}\n        </span>\n      </span>\n    </Button>\n  );\n}\n\n/** A secondary action, such as saving the product for later. */\nexport function ProductDetailSecondaryAction({ className, ...props }: ComponentProps<\"button\">) {\n  const { variant } = useDetail(\"ProductDetailSecondaryAction\");\n  return (\n    <Button\n      type=\"button\"\n      variant=\"secondary\"\n      data-slot=\"product-detail-secondary-action\"\n      className={cn(\n        buttonClass,\n        \"cursor-pointer gap-1.5 bg-secondary px-4 text-secondary-foreground hover:bg-[color-mix(in_oklab,var(--secondary)_85%,var(--foreground))] has-[>svg]:px-4\",\n        variant === \"compact\" ? \"h-8\" : \"h-10\",\n        className,\n      )}\n      {...props}\n      data-kind=\"secondary\"\n    />\n  );\n}\n\n/** Delivery and returns facts, rendered as a description list. */\nexport function ProductDetailDelivery({ className, ...props }: ComponentProps<\"dl\">) {\n  const { variant } = useDetail(\"ProductDetailDelivery\");\n  return (\n    <dl\n      data-slot=\"product-detail-delivery\"\n      className={cn(\n        \"m-0 grid gap-0.5 bg-card p-1\",\n        variant === \"compact\" ? \"rounded-xl\" : \"rounded-[14px]\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport type ProductDetailDeliveryItemProps = ComponentProps<\"div\"> & {\n  label: ReactNode;\n  icon?: ReactNode;\n};\n\nexport function ProductDetailDeliveryItem({\n  label,\n  icon,\n  children,\n  className,\n  ...props\n}: ProductDetailDeliveryItemProps) {\n  const { variant } = useDetail(\"ProductDetailDeliveryItem\");\n  return (\n    <div\n      data-slot=\"product-detail-delivery-item\"\n      className={cn(\n        \"grid gap-x-2.5 gap-y-0.5\",\n        icon ? \"grid-cols-[20px_minmax(0,1fr)]\" : \"grid-cols-[minmax(0,1fr)]\",\n        variant === \"compact\" ? \"rounded-lg px-2.5 py-2\" : \"rounded-[10px] px-3 py-2.5\",\n        className,\n      )}\n      {...props}\n    >\n      {icon ? (\n        <span aria-hidden=\"true\" className=\"row-span-2 pt-px text-muted-foreground\">\n          {icon}\n        </span>\n      ) : null}\n      <dt className=\"font-medium\">{label}</dt>\n      <dd className=\"m-0 text-[12.5px] text-muted-foreground\">{children}</dd>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "@components/uai/product-detail.tsx"
    }
  ],
  "categories": [
    "commerce",
    "product"
  ],
  "type": "registry:block"
}