# Add the "Cart Summary" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/cart-summary) to this Pantheon Content Publisher (P1) Next.js project. Cart as a real table with quantity inputs, remove links, a promo code form and an order summary with checkout link.

## Steps

1. Create `components/puck/cart-summary-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 { cartSummaryBlock } from "./components/puck/cart-summary-block";`
3. Register it under `components` as `CartSummaryBlock: cartSummaryBlock`.
4. Add `"CartSummaryBlock"` 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/cart-summary-block.tsx`

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

/**
 * Cart Summary — a shopping cart as a real table (item, price, quantity, line total) with an
 * update-quantities form, remove links, a promo code form and an order summary. No JavaScript.
 * Register: `CartSummaryBlock: cartSummaryBlock` in puck.config.tsx.
 */

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

type LineItem = {
  name: string;
  variant: string;
  sku: string;
  unitPrice: string;
  quantity: string;
  lineTotal: string;
  href: string;
  removeHref: string;
  imageUrl: string;
  imageAlt: string;
};

type SummaryRow = { label: string; value: string };

export type CartSummaryProps = {
  heading: string;
  headingLevel: Heading;
  items: LineItem[];
  updateAction: string;
  updateLabel: string;
  summaryHeading: string;
  rows: SummaryRow[];
  totalLabel: string;
  total: string;
  promoAction: string;
  checkoutLabel: string;
  checkoutHref: string;
  continueLabel: string;
  continueHref: string;
  note: string;
};

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

const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600";

export const cartSummaryBlock: ComponentConfig<CartSummaryProps> = {
  label: "Cart Summary",
  fields: {
    heading: { type: "text", label: "Heading" },
    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." },
    },
    items: {
      type: "array",
      label: "Line items",
      min: 0,
      max: 20,
      getItemSummary: (item) => `${item?.name || "Item"}${item?.quantity ? ` × ${item.quantity}` : ""}`,
      defaultItemProps: { name: "New item", variant: "", sku: "", unitPrice: "$10.00", quantity: "1", lineTotal: "$10.00", href: "#", removeHref: "#", imageUrl: "https://picsum.photos/seed/cartitem/300/300", imageAlt: "" },
      arrayFields: {
        name: { type: "text", label: "Name" },
        variant: { type: "text", label: "Options", metadata: { help: "Such as \"Forest green · Oversized\". Leave blank if none." } },
        sku: { type: "text", label: "SKU", metadata: { help: "Sent with the update form as sku[] so your cart knows which quantity is which." } },
        unitPrice: { type: "text", label: "Unit price" },
        quantity: { type: "text", label: "Quantity", metadata: { help: "Starting value of the quantity box. Can be bound to a data source." } },
        lineTotal: { type: "text", label: "Line total" },
        href: { type: "text", label: "Product link" },
        removeHref: { type: "text", label: "Remove link", metadata: { help: "A URL that removes this item, such as /shop/cart/remove?sku=NHM-5120." } },
        imageUrl: { type: "text", label: "Image URL" },
        imageAlt: { type: "text", label: "Image alt text", metadata: { help: "Leave blank if the photo only repeats the item name." } },
      },
      metadata: { help: "Usually bound to your cart data source. With no items, an empty-cart message shows instead." },
    },
    updateAction: { type: "text", label: "Update cart URL", metadata: { help: "Sent with POST using sku[] and quantity[] for every line." } },
    updateLabel: { type: "text", label: "Update button text" },
    summaryHeading: { type: "text", label: "Summary heading" },
    rows: {
      type: "array",
      label: "Summary rows",
      min: 0,
      max: 8,
      getItemSummary: (item) => `${item?.label || "Row"}: ${item?.value || "—"}`,
      defaultItemProps: { label: "Shipping", value: "$0.00" },
      arrayFields: {
        label: { type: "text", label: "Label" },
        value: { type: "text", label: "Amount", metadata: { help: "Shown as typed. Can be bound to a data source." } },
      },
      metadata: { help: "Subtotal, discounts, shipping and tax, in order." },
    },
    totalLabel: { type: "text", label: "Total label" },
    total: { type: "text", label: "Total", metadata: { help: "Shown as typed. Can be bound to a data source." } },
    promoAction: { type: "text", label: "Promo code URL", metadata: { help: "Where the promo code form posts, using the field name code. Leave blank to hide the form." } },
    checkoutLabel: { type: "text", label: "Checkout button text" },
    checkoutHref: { type: "text", label: "Checkout link" },
    continueLabel: { type: "text", label: "Keep shopping text", metadata: { help: "Leave blank to hide the link." } },
    continueHref: { type: "text", label: "Keep shopping link" },
    note: { type: "textarea", label: "Note", metadata: { help: "Small print under the summary. Leave blank to hide it." } },
  },
  defaultProps: {
    heading: "Your cart",
    headingLevel: "h2",
    items: [
      {
        name: "Herbarium Canvas Tote",
        variant: "Forest green · Standard",
        sku: "NHM-5120-GRN",
        unitPrice: "$32.00",
        quantity: "1",
        lineTotal: "$32.00",
        href: "/shop/herbarium-tote",
        removeHref: "/shop/cart/remove?sku=NHM-5120-GRN",
        imageUrl: "https://picsum.photos/seed/canvastote/300/300",
        imageAlt: "",
      },
      {
        name: "Mineral Discovery Kit",
        variant: "Ages 8+",
        sku: "NHM-3307",
        unitPrice: "$34.00",
        quantity: "2",
        lineTotal: "$68.00",
        href: "/shop/mineral-kit",
        removeHref: "/shop/cart/remove?sku=NHM-3307",
        imageUrl: "https://picsum.photos/seed/minerals/300/300",
        imageAlt: "",
      },
      {
        name: "Ohio Valley Birds Field Guide",
        variant: "Paperback",
        sku: "NHM-2210",
        unitPrice: "$18.00",
        quantity: "1",
        lineTotal: "$18.00",
        href: "/shop/ohio-valley-birds",
        removeHref: "/shop/cart/remove?sku=NHM-2210",
        imageUrl: "https://picsum.photos/seed/fieldguide/300/300",
        imageAlt: "",
      },
    ],
    updateAction: "/shop/cart/update",
    updateLabel: "Update quantities",
    summaryHeading: "Order summary",
    rows: [
      { label: "Subtotal", value: "$118.00" },
      { label: "Member discount (10%)", value: "−$11.80" },
      { label: "Shipping", value: "Free" },
      { label: "Estimated tax", value: "$6.37" },
    ],
    totalLabel: "Total",
    total: "$112.57",
    promoAction: "/shop/cart/promo",
    checkoutLabel: "Check out",
    checkoutHref: "/shop/checkout",
    continueLabel: "Keep shopping",
    continueHref: "/shop",
    note: "Amounts shown are sample data. Shipping is free on orders over $75. Every purchase supports free school field trips.",
  },
  render: ({ id, heading, headingLevel, items, updateAction, updateLabel, summaryHeading, rows, totalLabel, total, promoAction, checkoutLabel, checkoutHref, continueLabel, continueHref, note }) => {
    const H = headingLevel || "h2";
    const Sub = childHeading[H] || "h3";
    const uid = `cs-${id || "cart"}`;
    const lines = (items ?? []).filter((it) => it?.name);
    const summary = (rows ?? []).filter((r) => r?.label);

    return (
      <section className="bg-neutral-50 px-4 py-16 sm:px-6 sm:py-20 lg:px-8 lg:py-24">
        <div className="mx-auto max-w-6xl">
          {heading ? (
            <H className="flex flex-wrap items-baseline gap-x-3 text-3xl font-semibold tracking-tight text-neutral-950 sm:text-4xl">
              {heading}
              {lines.length ? (
                <span className="text-base font-medium tracking-normal text-neutral-600">
                  {lines.length} {lines.length === 1 ? "item" : "items"}
                </span>
              ) : null}
            </H>
          ) : null}

          <div className={`grid grid-cols-1 items-start gap-10 lg:grid-cols-12 lg:gap-12 ${heading ? "mt-10" : ""}`}>
            <div className="lg:col-span-8">
              {lines.length ? (
                <form action={updateAction || undefined} method="post">
                  <div className="relative overflow-x-auto rounded-2xl bg-white ring-1 ring-neutral-200">
                    <table className="w-full text-left text-sm">
                      <caption className="sr-only">Items in your cart, with price, quantity and total</caption>
                      <thead className="border-b border-neutral-200 text-xs font-semibold tracking-wide text-neutral-600 uppercase">
                        <tr>
                          <th scope="col" className="py-3 pr-2 pl-4 sm:pl-6">Item</th>
                          <th scope="col" className="hidden px-3 py-3 text-right sm:table-cell">Price</th>
                          <th scope="col" className="px-2 py-3 text-center">Qty</th>
                          <th scope="col" className="py-3 pr-4 pl-2 text-right sm:pr-6">Total</th>
                        </tr>
                      </thead>
                      <tbody className="divide-y divide-neutral-200">
                        {lines.map((it, i) => {
                          const qtyId = `${uid}-qty-${i}`;
                          return (
                            <tr key={`${it.sku || it.name}-${i}`} className="align-top">
                              <th scope="row" className="py-4 pr-2 pl-4 font-normal sm:py-5 sm:pl-6">
                                <div className="flex gap-3 sm:gap-4">
                                  {it.imageUrl ? (
                                    <img src={it.imageUrl} alt={it.imageAlt || ""} className="hidden size-20 shrink-0 rounded-lg bg-neutral-100 object-cover ring-1 ring-neutral-950/5 sm:block" />
                                  ) : null}
                                  <div className="min-w-0">
                                    <a href={it.href || "#"} className={`rounded-sm text-base leading-6 font-semibold break-words text-neutral-950 hover:text-indigo-700 ${focusRing}`}>
                                      {it.name}
                                    </a>
                                    {it.variant ? <p className="mt-0.5 text-sm leading-5 text-neutral-600">{it.variant}</p> : null}
                                    {it.unitPrice ? <p className="mt-0.5 text-sm leading-5 text-neutral-600 tabular-nums sm:hidden">{it.unitPrice} each</p> : null}
                                    {it.removeHref ? (
                                      <a href={it.removeHref} className={`-mx-1 mt-1 inline-flex min-h-11 items-center rounded-sm px-1 text-sm font-medium text-indigo-700 underline-offset-4 hover:underline ${focusRing}`}>
                                        Remove<span className="sr-only"> {it.name}</span>
                                      </a>
                                    ) : null}
                                  </div>
                                </div>
                              </th>
                              <td className="hidden px-3 py-5 text-right text-neutral-700 tabular-nums sm:table-cell">{it.unitPrice}</td>
                              <td className="px-2 py-4 text-center sm:py-5">
                                {it.sku ? <input type="hidden" name="sku[]" value={it.sku} /> : null}
                                <label htmlFor={qtyId} className="sr-only">
                                  Quantity of {it.name}
                                </label>
                                <input
                                  id={qtyId}
                                  name="quantity[]"
                                  type="number"
                                  inputMode="numeric"
                                  min="0"
                                  step="1"
                                  defaultValue={(it.quantity || "1").replace(/[^\d]/g, "") || "1"}
                                  className="mx-auto block min-h-11 w-16 rounded-lg border-0 bg-white px-2 py-2 text-center text-base text-neutral-950 tabular-nums ring-1 ring-neutral-300 ring-inset focus:ring-2 focus:ring-indigo-600 focus:outline-none"
                                />
                              </td>
                              <td className="py-4 pr-4 pl-2 text-right text-base font-semibold text-neutral-950 tabular-nums sm:py-5 sm:pr-6">{it.lineTotal || "—"}</td>
                            </tr>
                          );
                        })}
                      </tbody>
                    </table>
                  </div>
                  <div className="mt-4 flex flex-col-reverse gap-3 sm:flex-row sm:items-center sm:justify-between">
                    {continueLabel ? (
                      <a href={continueHref || "#"} className={`group inline-flex min-h-11 items-center gap-1.5 self-start rounded px-1 text-sm font-semibold text-indigo-700 hover:text-indigo-900 ${focusRing}`}>
                        <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 transition group-hover:-translate-x-0.5">
                          <path fillRule="evenodd" d="M17 10a.75.75 0 0 1-.75.75H5.612l3.158 3.04a.75.75 0 1 1-1.04 1.08l-4.5-4.25a.75.75 0 0 1 0-1.08l4.5-4.25a.75.75 0 1 1 1.04 1.08L5.612 9.25H16.25A.75.75 0 0 1 17 10Z" clipRule="evenodd" />
                        </svg>
                        {continueLabel}
                      </a>
                    ) : (
                      <span />
                    )}
                    <button type="submit" className={`inline-flex min-h-11 items-center justify-center rounded-lg bg-white px-5 py-2.5 text-sm font-semibold text-neutral-950 shadow-xs ring-1 ring-neutral-300 ring-inset hover:bg-neutral-50 ${focusRing}`}>
                      {updateLabel || "Update quantities"}
                    </button>
                  </div>
                  <p className="mt-2 text-sm text-neutral-600 sm:text-right">Set a quantity to 0 to remove that item.</p>
                </form>
              ) : (
                <div className="rounded-2xl bg-white px-6 py-12 text-center ring-1 ring-neutral-200">
                  <p className="text-base font-semibold text-neutral-950">Your cart is empty.</p>
                  {continueLabel ? (
                    <a href={continueHref || "#"} className={`mt-4 inline-flex min-h-11 items-center rounded px-1 text-sm font-semibold text-indigo-700 hover:text-indigo-900 ${focusRing}`}>
                      {continueLabel}
                    </a>
                  ) : null}
                </div>
              )}
            </div>

            <aside aria-labelledby={summaryHeading ? `${uid}-summary` : undefined} aria-label={summaryHeading ? undefined : "Order summary"} className="lg:col-span-4 lg:sticky lg:top-8">
              <div className="rounded-2xl bg-white p-6 ring-1 ring-neutral-200 sm:p-8">
                {summaryHeading ? (
                  <Sub id={`${uid}-summary`} className="text-lg leading-7 font-semibold text-neutral-950">
                    {summaryHeading}
                  </Sub>
                ) : null}
                {summary.length || total ? (
                  <dl className={`space-y-3 text-sm ${summaryHeading ? "mt-6" : ""}`}>
                    {summary.map((r, i) => (
                      <div key={`${r.label}-${i}`} className="flex items-baseline justify-between gap-4">
                        <dt className="text-neutral-600">{r.label}</dt>
                        <dd className="font-medium text-neutral-950 tabular-nums">{r.value || "—"}</dd>
                      </div>
                    ))}
                    {total ? (
                      <div className="flex items-baseline justify-between gap-4 border-t border-neutral-200 pt-4">
                        <dt className="text-base font-semibold text-neutral-950">{totalLabel || "Total"}</dt>
                        <dd className="text-2xl font-semibold tracking-tight text-neutral-950 tabular-nums">{total}</dd>
                      </div>
                    ) : null}
                  </dl>
                ) : null}

                {promoAction ? (
                  <form action={promoAction} method="post" className="mt-6 border-t border-neutral-200 pt-6">
                    <label htmlFor={`${uid}-promo`} className="block text-sm leading-6 font-medium text-neutral-900">
                      Promo or member code <span className="font-normal text-neutral-600">(optional)</span>
                    </label>
                    <div className="mt-2 flex gap-2">
                      <input
                        id={`${uid}-promo`}
                        name="code"
                        type="text"
                        autoComplete="off"
                        autoCapitalize="characters"
                        className="block min-h-11 w-full min-w-0 rounded-lg border-0 bg-white px-3.5 py-2.5 text-base text-neutral-950 uppercase ring-1 ring-neutral-300 ring-inset focus:ring-2 focus:ring-indigo-600 focus:outline-none"
                      />
                      <button type="submit" className={`inline-flex min-h-11 shrink-0 items-center rounded-lg bg-neutral-950 px-4 text-sm font-semibold text-white hover:bg-neutral-800 ${focusRing}`}>
                        Apply
                      </button>
                    </div>
                  </form>
                ) : null}

                {checkoutLabel && lines.length ? (
                  <a
                    href={checkoutHref || "#"}
                    className={`mt-6 flex min-h-12 w-full 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 ${focusRing}`}
                  >
                    <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4">
                      <path fillRule="evenodd" d="M10 1a4.5 4.5 0 0 0-4.5 4.5V9H5a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-6a2 2 0 0 0-2-2h-.5V5.5A4.5 4.5 0 0 0 10 1Zm3 8V5.5a3 3 0 1 0-6 0V9h6Z" clipRule="evenodd" />
                    </svg>
                    {checkoutLabel}
                  </a>
                ) : null}
                {note ? <p className="mt-6 text-xs leading-5 text-pretty text-neutral-600">{note}</p> : null}
              </div>
            </aside>
          </div>
        </div>
      </section>
    );
  },
};
```
