# Add the "Comparison Table" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/comparison-table) to this Pantheon Content Publisher (P1) Next.js project. Compare two to four plans or options feature by feature in a real table with a pinned first column.

## Steps

1. Create `components/puck/comparison-table-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 { comparisonTableBlock } from "./components/puck/comparison-table-block";`
3. Register it under `components` as `ComparisonTableBlock: comparisonTableBlock`.
4. Add `"ComparisonTableBlock"` to the best-fitting entry in `categories` (this block's library category is "Content"). 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/comparison-table-block.tsx`

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

/**
 * Comparison Table — compares two to four options (plans, memberships, rental spaces) feature
 * by feature in a real <table>. Cells read "yes", "no" or any short text; the feature column stays
 * pinned while the table scrolls sideways on phones. Register: `ComparisonTableBlock: comparisonTableBlock`.
 */

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

export type ComparisonTableProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  options: { name: string; detail: string; ctaLabel: string; ctaHref: string }[];
  highlight: "none" | "1" | "2" | "3" | "4";
  highlightLabel: string;
  rows: { group: string; feature: string; note: string; values: string }[];
  footnote: string;
};

const YES = /^(?:yes|y|true|included|✓|✔)$/i;
const NO = /^(?:no|n|false|—|–|-|not included|✗|✕)$/i;

function Cell({ value }: { value: string }) {
  const v = value.trim();
  if (!v) {
    return (
      <>
        <span aria-hidden="true" className="text-neutral-400">·</span>
        <span className="sr-only">Not listed</span>
      </>
    );
  }
  if (YES.test(v)) {
    return (
      <>
        <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="mx-auto size-5 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>
        <span className="sr-only">Included</span>
      </>
    );
  }
  if (NO.test(v)) {
    return (
      <>
        <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="mx-auto size-5 text-neutral-400">
          <path d="M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z" />
        </svg>
        <span className="sr-only">Not included</span>
      </>
    );
  }
  return <span className="text-sm leading-6 text-neutral-800">{v}</span>;
}

export const comparisonTableBlock: ComponentConfig<ComparisonTableProps> = {
  label: "Comparison Table",
  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." },
    },
    intro: { type: "textarea", label: "Intro" },
    options: {
      type: "array",
      label: "Options (columns)",
      min: 2,
      max: 4,
      getItemSummary: (item) => item?.name?.slice(0, 40) || "Option",
      defaultItemProps: { name: "New option", detail: "", ctaLabel: "", ctaHref: "" },
      arrayFields: {
        name: { type: "text", label: "Name" },
        detail: { type: "text", label: "Detail", metadata: { help: "Price or one-line summary under the name, like “$45 / 4 hours”. Leave blank to hide it." } },
        ctaLabel: { type: "text", label: "Button text", metadata: { help: "Shown at the foot of the column. Leave blank to hide it." } },
        ctaHref: { type: "text", label: "Button link" },
      },
      metadata: { help: "Two to four plans or options, shown as columns in this order." },
    },
    highlight: {
      type: "select",
      label: "Highlight column",
      options: [
        { label: "None", value: "none" },
        { label: "Option 1", value: "1" },
        { label: "Option 2", value: "2" },
        { label: "Option 3", value: "3" },
        { label: "Option 4", value: "4" },
      ],
    },
    highlightLabel: { type: "text", label: "Highlight label", metadata: { help: "Badge on the highlighted column, like “Most booked”. Leave blank to hide it." } },
    rows: {
      type: "array",
      label: "Rows",
      min: 1,
      max: 40,
      getItemSummary: (item) => item?.feature?.slice(0, 48) || "Row",
      defaultItemProps: { group: "", feature: "New feature", note: "", values: "yes | no" },
      arrayFields: {
        group: { type: "text", label: "Group", metadata: { help: "Optional. When this changes from the row above, a group header row starts, like “Amenities”." } },
        feature: { type: "text", label: "Feature" },
        note: { type: "text", label: "Note", metadata: { help: "Small explanation under the feature name. Leave blank to hide it." } },
        values: {
          type: "text",
          label: "Values",
          metadata: { help: "One value per option, separated by | in column order. Write yes or no for a check or cross, or short text like “Up to 40”." },
        },
      },
    },
    footnote: { type: "textarea", label: "Footnote", metadata: { help: "Small print under the table, like fees or policies. Leave blank to hide it." } },
  },
  defaultProps: {
    heading: "Compare rental spaces",
    headingLevel: "h2",
    intro: "Every space can be booked online up to twelve months ahead. Resident rates are shown; non-residents pay 25% more.",
    options: [
      { name: "Picnic shelter", detail: "$45 per 4 hours", ctaLabel: "Book a shelter", ctaHref: "/rentals/shelters" },
      { name: "Community room", detail: "$60 per hour", ctaLabel: "Book a room", ctaHref: "/rentals/rooms" },
      { name: "Boathouse", detail: "$140 per hour", ctaLabel: "Request a date", ctaHref: "/rentals/boathouse" },
    ],
    highlight: "2",
    highlightLabel: "Most booked",
    rows: [
      { group: "Capacity", feature: "Guests", note: "", values: "Up to 60 | Up to 80 | Up to 150" },
      { group: "Capacity", feature: "Tables and chairs", note: "", values: "yes | yes | yes" },
      { group: "Amenities", feature: "Electricity", note: "", values: "One outlet | yes | yes" },
      { group: "Amenities", feature: "Kitchen", note: "Refrigerator, sink and warming oven", values: "no | yes | yes" },
      { group: "Amenities", feature: "Restrooms on site", note: "", values: "Seasonal | yes | yes" },
      { group: "Amenities", feature: "Projector and screen", note: "", values: "no | yes | Add-on" },
      { group: "Policies", feature: "Alcohol permitted", note: "Requires a permit and event insurance", values: "no | no | yes" },
      { group: "Policies", feature: "Accessible entrance and parking", note: "", values: "yes | yes | yes" },
    ],
    footnote: "A refundable $100 deposit is required for all indoor rentals. Fee assistance is available for nonprofit and neighborhood groups.",
  },
  render: ({ id, heading, headingLevel, intro, options, highlight, highlightLabel, rows, footnote }) => {
    const H = headingLevel || "h2";
    const uid = `p1-compare-${id}`;
    const cols = (options ?? []).filter((o) => o?.name).slice(0, 4);
    const list = (rows ?? []).filter((r) => r?.feature);
    const hi = highlight && highlight !== "none" ? Number(highlight) - 1 : -1;
    const hasCtas = cols.some((c) => c.ctaLabel);
    if (cols.length === 0 && !heading) return <></>;

    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 max-w-6xl">
          {heading || intro ? (
            <div className="max-w-2xl">
              {heading ? (
                <H id={`${uid}-title`} className="text-3xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-4xl">
                  {heading}
                </H>
              ) : null}
              {intro ? <p className="mt-4 text-lg leading-8 text-pretty text-neutral-600">{intro}</p> : null}
            </div>
          ) : null}

          {cols.length > 0 ? (
            <div
              role="region"
              aria-labelledby={heading ? `${uid}-title` : undefined}
              aria-label={heading ? undefined : "Comparison table"}
              tabIndex={0}
              className={`${heading || intro ? "mt-10 sm:mt-12" : ""} -mx-4 relative overflow-x-auto focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 sm:mx-0 sm:rounded-2xl sm:ring-1 sm:ring-neutral-950/10`}
            >
              <table className="w-full min-w-xl border-separate border-spacing-0 text-left">
                <caption className="sr-only">{heading || "Comparison of options"}</caption>
                <thead>
                  <tr>
                    <td className="sticky left-0 z-10 w-2/5 border-b border-neutral-200 bg-white px-4 py-5 sm:px-6" />
                    {cols.map((col, c) => {
                      const on = c === hi;
                      return (
                        <th
                          key={`${col.name}-${c}`}
                          scope="col"
                          className={`border-b px-4 py-5 text-center align-bottom ${on ? "border-indigo-200 bg-indigo-50" : "border-neutral-200"}`}
                        >
                          {on && highlightLabel ? (
                            <span className="mb-2 inline-block rounded-full bg-indigo-600 px-2.5 py-0.5 text-xs font-semibold text-white">{highlightLabel}</span>
                          ) : null}
                          <span className="block text-base font-semibold text-neutral-950">{col.name}</span>
                          {col.detail ? <span className="mt-1 block text-sm font-normal text-neutral-600">{col.detail}</span> : null}
                        </th>
                      );
                    })}
                  </tr>
                </thead>
                <tbody>
                  {list.map((row, r) => {
                    const values = (row.values || "").split("|");
                    const group = row.group?.trim();
                    const startsGroup = Boolean(group) && group !== list[r - 1]?.group?.trim();
                    return [
                      startsGroup ? (
                        <tr key={`g-${r}`}>
                          <th
                            scope="colgroup"
                            colSpan={cols.length + 1}
                            className="border-b border-neutral-200 bg-neutral-50 px-4 pt-6 pb-2 text-left text-xs font-semibold tracking-widest text-neutral-600 uppercase sm:px-6"
                          >
                            {/* Sticky inner span keeps the group label visible while the table scrolls sideways. */}
                            <span className="sticky left-4 inline-block sm:left-6">{group}</span>
                          </th>
                        </tr>
                      ) : null,
                      <tr key={`r-${r}`}>
                        <th scope="row" className="sticky left-0 z-10 border-b border-neutral-200 bg-white px-4 py-4 align-top font-normal sm:px-6">
                          <span className="block text-sm font-medium text-neutral-950">{row.feature}</span>
                          {row.note ? <span className="mt-0.5 block text-xs leading-5 text-neutral-600">{row.note}</span> : null}
                        </th>
                        {cols.map((col, c) => (
                          <td
                            key={`${col.name}-${c}`}
                            className={`border-b px-4 py-4 text-center align-top ${c === hi ? "border-indigo-100 bg-indigo-50/60" : "border-neutral-200"}`}
                          >
                            <Cell value={values[c] ?? ""} />
                          </td>
                        ))}
                      </tr>,
                    ];
                  })}
                </tbody>
                {hasCtas ? (
                  <tfoot>
                    <tr>
                      <td className="sticky left-0 z-10 bg-white px-4 py-5 sm:px-6" />
                      {cols.map((col, c) => (
                        <td key={`${col.name}-${c}`} className={`px-4 py-5 text-center ${c === hi ? "bg-indigo-50" : ""}`}>
                          {col.ctaLabel ? (
                            <a
                              href={col.ctaHref || "#"}
                              className={`inline-flex min-h-11 items-center justify-center rounded-lg px-4 py-2.5 text-sm font-semibold focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 ${
                                c === hi ? "bg-indigo-600 text-white shadow-sm hover:bg-indigo-500" : "bg-white text-neutral-900 ring-1 ring-neutral-300 ring-inset hover:bg-neutral-50"
                              }`}
                            >
                              {col.ctaLabel}
                              <span className="sr-only">: {col.name}</span>
                            </a>
                          ) : null}
                        </td>
                      ))}
                    </tr>
                  </tfoot>
                ) : null}
              </table>
            </div>
          ) : null}

          {footnote ? <p className="mt-6 max-w-3xl text-sm leading-6 text-pretty text-neutral-600">{footnote}</p> : null}
        </div>
      </section>
    );
  },
};
```
