# Add the "Product Detail" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/product-detail) to this Pantheon Content Publisher (P1) Next.js project. Photo gallery, price, option pills as radio groups, quantity and an add-to-cart form, with expandable care and returns details.

## Steps

1. Create `components/puck/product-detail-block.tsx` with the exact file contents below. If `components/puck/` doesn't exist, find the folder where this project keeps its Puck components (look at the imports in `puck.config.tsx`) and put it there.
2. In `puck.config.tsx`, import it: `import { productDetailBlock } from "./components/puck/product-detail-block";`
3. Register it under `components` as `ProductDetailBlock: productDetailBlock`.
4. Add `"ProductDetailBlock"` to the best-fitting entry in `categories` (this block's library category is "Ecommerce"). Create a category only if none fits.
5. Run the project's type check (usually `pnpm typecheck`) and resolve anything project-specific.
6. If `package.json` has a `sync:registry` script, tell the user it must run (or that CI will run it) before the new component appears in the P1 editor.

## Rules

- Do not add dependencies. The block is self-contained by design: one type-only import from `@puckeditor/core`, Tailwind v4 classes, no client JavaScript.
- Keep the files as-is unless the user asks for changes. The accent color is `indigo-*`; if the project has brand colors, offer to swap them with a find-and-replace on `indigo-`.
- Images are plain `imageUrl` + `imageAlt` text fields. If this project defines a P1 media-library field (search for `"p1-media"`), offer to switch to it.
- Don't change prop names in `defaultProps`. Content editors' saved pages depend on them.

## File: `components/puck/product-detail-block.tsx`

```tsx
import type { ComponentConfig } from "@puckeditor/core";

/**
 * Product Detail — a shop item page: photo gallery, price, variant choices as radio pills,
 * quantity and an add-to-cart form that posts to your cart, plus expandable details. No JavaScript.
 * Register: `ProductDetailBlock: productDetailBlock` in puck.config.tsx.
 */

type Heading = "h1" | "h2" | "h3" | "h4";

type Photo = { imageUrl: string; imageAlt: string };
type VariantGroup = { name: string; options: string };
type Detail = { title: string; body: string };

export type ProductDetailProps = {
  breadcrumb: string;
  name: string;
  headingLevel: Heading;
  price: string;
  compareAt: string;
  rating: string;
  description: string;
  photos: Photo[];
  variants: VariantGroup[];
  cartAction: string;
  sku: string;
  maxQuantity: string;
  addLabel: string;
  stockNote: string;
  memberNote: string;
  details: Detail[];
};

const childHeading: Record<Heading, "h2" | "h3" | "h4" | "h5"> = { h1: "h2", h2: "h3", h3: "h4", h4: "h5" };

const fieldName = (s: string) => (s || "option").toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_|_$/g, "") || "option";

export const productDetailBlock: ComponentConfig<ProductDetailProps> = {
  label: "Product Detail",
  fields: {
    breadcrumb: { type: "text", label: "Category line", metadata: { help: "Small line above the name, such as the shop section. Leave blank to hide it." } },
    name: { type: "text", label: "Product name" },
    headingLevel: {
      type: "select",
      label: "Heading level",
      options: [
        { label: "H1", value: "h1" },
        { label: "H2", value: "h2" },
        { label: "H3", value: "h3" },
        { label: "H4", value: "h4" },
      ],
      metadata: { help: "Sets the page outline for screen readers and search. The look doesn't change. Use H1 on a product's own page." },
    },
    price: { type: "text", label: "Price", metadata: { help: "Shown as typed, such as $42.00. Can be bound to a data source." } },
    compareAt: { type: "text", label: "Original price", metadata: { help: "Shown struck through when the item is on sale. Leave blank otherwise." } },
    rating: { type: "text", label: "Rating line", metadata: { help: "Such as \"4.8 out of 5 from 63 reviews\". Leave blank to hide it." } },
    description: { type: "textarea", label: "Description", metadata: { help: "Blank lines start new paragraphs." } },
    photos: {
      type: "array",
      label: "Photos",
      min: 1,
      max: 5,
      getItemSummary: (item) => item?.imageAlt || "Photo",
      defaultItemProps: { imageUrl: "https://picsum.photos/seed/productview/1000/1000", imageAlt: "" },
      arrayFields: {
        imageUrl: { type: "text", label: "Image URL" },
        imageAlt: { type: "text", label: "Alt text", metadata: { help: "Describe what this view shows, such as \"Back of the tote\"." } },
      },
      metadata: { help: "The first photo is the large one. Up to four more appear as thumbnails that jump to a full-size view." },
    },
    variants: {
      type: "array",
      label: "Options",
      min: 0,
      max: 3,
      getItemSummary: (item) => item?.name || "Option group",
      defaultItemProps: { name: "Size", options: "Small\nMedium\nLarge" },
      arrayFields: {
        name: { type: "text", label: "Option name", metadata: { help: "Such as Size or Color. Also used as the form field name." } },
        options: { type: "textarea", label: "Choices", metadata: { help: "One choice per line. The first is selected at first." } },
      },
    },
    cartAction: { type: "text", label: "Cart URL", metadata: { help: "Where the form posts: sku, quantity and one field per option group (for example size)." } },
    sku: { type: "text", label: "SKU" },
    maxQuantity: { type: "text", label: "Maximum quantity", metadata: { help: "Highest number a visitor can add at once. Leave blank for no limit." } },
    addLabel: { type: "text", label: "Button text" },
    stockNote: { type: "text", label: "Stock note", metadata: { help: "Such as \"In stock, ships in 2 business days\". Can be bound to a data source." } },
    memberNote: { type: "text", label: "Member note", metadata: { help: "Shown in a highlighted line under the button. Leave blank to hide it." } },
    details: {
      type: "array",
      label: "Details",
      min: 0,
      max: 6,
      getItemSummary: (item) => item?.title || "Detail",
      defaultItemProps: { title: "Care", body: "" },
      arrayFields: {
        title: { type: "text", label: "Title" },
        body: { type: "textarea", label: "Text" },
      },
      metadata: { help: "Expandable sections such as materials, dimensions and returns." },
    },
  },
  defaultProps: {
    breadcrumb: "Museum Store · Bags & Totes",
    name: "Herbarium Canvas Tote",
    headingLevel: "h2",
    price: "$32.00",
    compareAt: "",
    rating: "4.8 out of 5 from 63 reviews (sample data)",
    description:
      "Printed with pressed ferns from our 1890s herbarium sheets, this heavyweight tote is sized for a laptop, a sketchbook and a field guide.\n\nScreen-printed by hand in Louisville with water-based inks. Every sale supports the conservation of our botanical collection.",
    photos: [
      { imageUrl: "https://picsum.photos/seed/canvastote/1000/1000", imageAlt: "Natural canvas tote printed with dark green fern fronds" },
      { imageUrl: "https://picsum.photos/seed/totedetail/1000/1000", imageAlt: "Close view of the fern print and stitched handle" },
      { imageUrl: "https://picsum.photos/seed/toteinside/1000/1000", imageAlt: "Inside pocket of the tote holding a phone and pencils" },
      { imageUrl: "https://picsum.photos/seed/totecarry/1000/1000", imageAlt: "Visitor carrying the tote through a museum gallery" },
    ],
    variants: [
      { name: "Color", options: "Natural\nForest green\nCharcoal" },
      { name: "Size", options: "Standard\nOversized" },
    ],
    cartAction: "/shop/cart",
    sku: "NHM-5120",
    maxQuantity: "10",
    addLabel: "Add to cart",
    stockNote: "In stock · ships in 2 business days",
    memberNote: "Members save 10% — sign in at checkout.",
    details: [
      { title: "Materials and size", body: "16 oz organic cotton canvas. 15 × 16 × 4 in with 24 in handles. Inside zip pocket." },
      { title: "Care", body: "Spot clean or machine wash cold inside out. Hang to dry. Do not bleach." },
      { title: "Shipping and returns", body: "Standard shipping is $6.95, free on orders over $75. Unused items can be returned within 30 days for a full refund." },
    ],
  },
  render: ({ id, breadcrumb, name, headingLevel, price, compareAt, rating, description, photos, variants, cartAction, sku, maxQuantity, addLabel, stockNote, memberNote, details }) => {
    const H = headingLevel || "h2";
    const Sub = childHeading[H] || "h3";
    const uid = `pd-${id || "product"}`;
    const pics = (photos ?? []).filter((p) => p?.imageUrl).slice(0, 5);
    const groups = (variants ?? [])
      .map((g) => ({ name: (g?.name || "").trim(), options: (g?.options || "").split("\n").map((o) => o.trim()).filter(Boolean) }))
      .filter((g) => g.name && g.options.length);
    const paras = (description || "").split(/\n\s*\n/).map((p) => p.trim()).filter(Boolean);
    const info = (details ?? []).filter((d) => d?.title);
    const max = (maxQuantity || "").replace(/[^\d]/g, "");
    const [main, ...thumbs] = pics;

    return (
      <section className="bg-white px-4 py-16 sm:px-6 sm:py-20 lg:px-8 lg:py-24">
        <div className="mx-auto grid max-w-7xl grid-cols-1 gap-10 lg:grid-cols-12 lg:gap-16">
          {main ? (
            <div className="lg:col-span-7">
              <div className="flex flex-col gap-4">
                {pics.map((p, i) => (
                  <img
                    key={`${p.imageUrl}-${i}`}
                    id={`${uid}-photo-${i}`}
                    src={p.imageUrl}
                    alt={p.imageAlt || ""}
                    className={`w-full scroll-mt-8 rounded-2xl bg-neutral-100 object-cover ring-1 ring-neutral-950/5 ${i === 0 ? "aspect-square" : "hidden aspect-square lg:block"}`}
                  />
                ))}
              </div>
              {thumbs.length ? (
                <ul role="list" aria-label="More photos" className="mt-4 grid grid-cols-4 gap-3 lg:hidden">
                  {thumbs.map((p, i) => (
                    <li key={`${p.imageUrl}-t-${i}`}>
                      <a
                        href={p.imageUrl}
                        className="block overflow-hidden rounded-lg ring-1 ring-neutral-200 hover:ring-indigo-400 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                      >
                        <img src={p.imageUrl} alt={p.imageAlt ? `View larger: ${p.imageAlt}` : `View photo ${i + 2}`} className="aspect-square w-full object-cover" />
                      </a>
                    </li>
                  ))}
                </ul>
              ) : null}
            </div>
          ) : null}

          <div className={main ? "lg:col-span-5" : "lg:col-span-8 lg:col-start-3"}>
            <div className="lg:sticky lg:top-8">
              {breadcrumb ? <p className="text-sm font-medium text-neutral-600">{breadcrumb}</p> : null}
              {name ? <H className={`text-3xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-4xl ${breadcrumb ? "mt-2" : ""}`}>{name}</H> : null}

              {price ? (
                <p className="mt-4 flex flex-wrap items-baseline gap-x-3 tabular-nums">
                  {compareAt ? <span className="sr-only">Sale price</span> : <span className="sr-only">Price</span>}
                  <span className={`text-3xl font-semibold tracking-tight ${compareAt ? "text-indigo-700" : "text-neutral-950"}`}>{price}</span>
                  {compareAt ? (
                    <>
                      <span className="sr-only">, was</span>
                      <s className="text-lg text-neutral-600">{compareAt}</s>
                    </>
                  ) : null}
                </p>
              ) : null}
              {rating ? (
                <p className="mt-2 flex items-center gap-2 text-sm text-neutral-600">
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 text-indigo-600">
                    <path fillRule="evenodd" d="M10.868 2.884c-.321-.772-1.415-.772-1.736 0l-1.83 4.401-4.753.381c-.833.067-1.171 1.107-.536 1.651l3.62 3.102-1.106 4.637c-.194.813.691 1.456 1.405 1.02L10 15.591l4.069 2.485c.713.436 1.598-.207 1.404-1.02l-1.106-4.637 3.62-3.102c.635-.544.297-1.584-.536-1.65l-4.752-.382-1.831-4.401Z" clipRule="evenodd" />
                  </svg>
                  {rating}
                </p>
              ) : null}

              {paras.length ? (
                <div className="mt-6 space-y-4 text-base leading-7 text-pretty text-neutral-700">
                  {paras.map((p, i) => (
                    <p key={i}>{p}</p>
                  ))}
                </div>
              ) : null}

              <form action={cartAction || undefined} method="post" className="mt-8 border-t border-neutral-200 pt-8">
                {sku ? <input type="hidden" name="sku" value={sku} /> : null}
                {groups.map((g, gi) => (
                  <fieldset key={`${g.name}-${gi}`} className={gi ? "mt-6" : ""}>
                    <legend className="text-sm leading-6 font-semibold text-neutral-950">{g.name}</legend>
                    <div className="mt-3 flex flex-wrap gap-2">
                      {g.options.map((o, oi) => (
                        <label
                          key={`${o}-${oi}`}
                          className="inline-flex min-h-11 cursor-pointer items-center rounded-full bg-white px-4 text-sm font-medium text-neutral-800 ring-1 ring-neutral-300 transition select-none ring-inset hover:ring-neutral-500 has-checked:bg-neutral-950 has-checked:text-white has-checked:ring-neutral-950 has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-indigo-600"
                        >
                          <input type="radio" name={fieldName(g.name)} value={o} defaultChecked={oi === 0} required className="sr-only" />
                          {o}
                        </label>
                      ))}
                    </div>
                  </fieldset>
                ))}

                <div className={`flex flex-col gap-3 sm:flex-row sm:items-end ${groups.length ? "mt-8" : ""}`}>
                  <div className="sm:w-28">
                    <label htmlFor={`${uid}-qty`} className="block text-sm leading-6 font-medium text-neutral-900">
                      Quantity
                    </label>
                    <input
                      id={`${uid}-qty`}
                      name="quantity"
                      type="number"
                      inputMode="numeric"
                      min="1"
                      max={max || undefined}
                      step="1"
                      defaultValue="1"
                      required
                      className="mt-2 block min-h-11 w-full rounded-lg border-0 bg-white px-3.5 py-2.5 text-base text-neutral-950 tabular-nums shadow-xs ring-1 ring-neutral-300 ring-inset focus:ring-2 focus:ring-indigo-600 focus:outline-none"
                    />
                  </div>
                  <button
                    type="submit"
                    aria-describedby={stockNote ? `${uid}-stock` : undefined}
                    className="inline-flex min-h-12 flex-1 items-center justify-center gap-2 rounded-lg bg-indigo-600 px-6 py-3 text-base font-semibold text-white shadow-xs transition hover:bg-indigo-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                  >
                    <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5">
                      <path fillRule="evenodd" d="M6 5v1H4.667a1.75 1.75 0 0 0-1.743 1.598l-.826 9.5A1.75 1.75 0 0 0 3.84 19H16.16a1.75 1.75 0 0 0 1.743-1.902l-.826-9.5A1.75 1.75 0 0 0 15.333 6H14V5a4 4 0 0 0-8 0Zm4-2.5A2.5 2.5 0 0 0 7.5 5v1h5V5A2.5 2.5 0 0 0 10 2.5ZM7.5 10a2.5 2.5 0 0 0 5 0V8.75a.75.75 0 0 1 1.5 0V10a4 4 0 0 1-8 0V8.75a.75.75 0 0 1 1.5 0V10Z" clipRule="evenodd" />
                    </svg>
                    {addLabel || "Add to cart"}
                  </button>
                </div>
                {stockNote ? (
                  <p id={`${uid}-stock`} className="mt-3 flex items-center gap-2 text-sm text-neutral-700">
                    <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 shrink-0 text-indigo-600">
                      <path fillRule="evenodd" d="M16.704 4.153a.75.75 0 0 1 .143 1.052l-8 10.5a.75.75 0 0 1-1.127.075l-4.5-4.5a.75.75 0 0 1 1.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 0 1 1.05-.143Z" clipRule="evenodd" />
                    </svg>
                    {stockNote}
                  </p>
                ) : null}
                {memberNote ? <p className="mt-4 rounded-lg bg-indigo-50 px-4 py-3 text-sm leading-6 font-medium text-indigo-900 ring-1 ring-indigo-600/10 ring-inset">{memberNote}</p> : null}
              </form>

              {info.length ? (
                <div className="mt-10 divide-y divide-neutral-200 border-y border-neutral-200">
                  {info.map((d, i) => (
                    <details key={`${d.title}-${i}`} className="group">
                      <summary className="flex min-h-14 cursor-pointer list-none items-center justify-between gap-4 rounded-sm py-3 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 [&::-webkit-details-marker]:hidden">
                        <Sub className="text-base font-semibold text-neutral-950">{d.title}</Sub>
                        <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5 shrink-0 text-neutral-500 transition group-open:rotate-45">
                          <path d="M10.75 4.75a.75.75 0 0 0-1.5 0v4.5h-4.5a.75.75 0 0 0 0 1.5h4.5v4.5a.75.75 0 0 0 1.5 0v-4.5h4.5a.75.75 0 0 0 0-1.5h-4.5v-4.5Z" />
                        </svg>
                      </summary>
                      {d.body ? <p className="pb-5 text-sm leading-6 text-pretty text-neutral-700">{d.body}</p> : null}
                    </details>
                  ))}
                </div>
              ) : null}
            </div>
          </div>
        </div>
      </section>
    );
  },
};
```
