# Add the "Tuition Breakdown" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/tuition-breakdown) to this Pantheon Content Publisher (P1) Next.js project. Cost-of-attendance table comparing two rates, with computed totals and a net price calculator link.

## Steps

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

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

/**
 * Tuition Breakdown — a cost-of-attendance table comparing two rates (in-state and
 * out-of-state by default), with totals worked out from the rows and a net price link.
 * Register: `TuitionBreakdownBlock: tuitionBreakdownBlock` in puck.config.tsx.
 */

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

type Row = { item: string; amountA: string; amountB: string };

export type TuitionBreakdownProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  badge: string;
  caption: string;
  columnA: string;
  columnB: string;
  rows: Row[];
  totalLabel: string;
  totalA: string;
  totalB: string;
  footnote: string;
  calculatorLabel: string;
  calculatorHref: string;
  calculatorText: string;
};

const currency = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", maximumFractionDigits: 0 });

function parseAmount(value: string | undefined): number | null {
  if (!value) return null;
  const cleaned = value.replace(/[^0-9.-]/g, "");
  if (!cleaned || !/\d/.test(cleaned)) return null;
  const n = Number.parseFloat(cleaned);
  return Number.isFinite(n) ? n : null;
}

function sum(rows: Row[], key: "amountA" | "amountB"): string {
  let total = 0;
  let found = false;
  for (const row of rows) {
    const n = parseAmount(row[key]);
    if (n !== null) {
      total += n;
      found = true;
    }
  }
  return found ? currency.format(total) : "—";
}

export const tuitionBreakdownBlock: ComponentConfig<TuitionBreakdownProps> = {
  label: "Tuition Breakdown",
  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" },
    badge: { type: "text", label: "Badge", metadata: { help: "Short label such as 2026–27 estimated. Leave blank to hide it." } },
    caption: { type: "text", label: "Table caption", metadata: { help: "Names the table for screen reader users and sits above it." } },
    columnA: { type: "text", label: "First column label" },
    columnB: { type: "text", label: "Second column label" },
    rows: {
      type: "array",
      label: "Cost rows",
      min: 1,
      max: 16,
      getItemSummary: (item) => item?.item || "Cost item",
      defaultItemProps: { item: "New cost", amountA: "$0", amountB: "$0" },
      arrayFields: {
        item: { type: "text", label: "Item" },
        amountA: { type: "text", label: "First column amount", metadata: { help: "Type it as it should appear, such as $11,240. Numbers here are added into the total." } },
        amountB: { type: "text", label: "Second column amount" },
      },
    },
    totalLabel: { type: "text", label: "Total row label", metadata: { help: "Leave blank to hide the total row." } },
    totalA: { type: "text", label: "First column total (override)", metadata: { help: "Leave blank to add up the rows automatically." } },
    totalB: { type: "text", label: "Second column total (override)", metadata: { help: "Leave blank to add up the rows automatically." } },
    footnote: { type: "textarea", label: "Footnote", metadata: { help: "Small print under the table. Leave blank to hide it." } },
    calculatorText: { type: "textarea", label: "Net price text", metadata: { help: "A sentence pointing families to the net price calculator. Leave blank to hide the panel." } },
    calculatorLabel: { type: "text", label: "Net price link text" },
    calculatorHref: { type: "text", label: "Net price link" },
  },
  defaultProps: {
    heading: "Cost of attendance",
    headingLevel: "h2",
    intro: "What a full-time undergraduate living on campus can expect to spend in a year. Grants and scholarships lower the price for many students.",
    badge: "2026–27 estimated",
    caption: "Estimated annual cost of attendance, 2026–27 (sample figures)",
    columnA: "In-state",
    columnB: "Out-of-state",
    rows: [
      { item: "Tuition", amountA: "$9,840", amountB: "$24,610" },
      { item: "Mandatory fees", amountA: "$1,420", amountB: "$1,420" },
      { item: "Housing (double room)", amountA: "$7,350", amountB: "$7,350" },
      { item: "Meal plan", amountA: "$4,980", amountB: "$4,980" },
      { item: "Books and supplies", amountA: "$1,050", amountB: "$1,050" },
      { item: "Transportation and personal", amountA: "$2,600", amountB: "$3,100" },
    ],
    totalLabel: "Estimated total",
    totalA: "",
    totalB: "",
    footnote: "Sample figures for illustration. Tuition and fees are set by the Board of Regents each spring; housing, meals and personal costs are university estimates and vary by student.",
    calculatorText: "The sticker price is only a starting point. Get a personal estimate after grants and scholarships in about ten minutes.",
    calculatorLabel: "Use the net price calculator",
    calculatorHref: "/financial-aid/net-price-calculator",
  },
  render: ({
    id,
    heading,
    headingLevel,
    intro,
    badge,
    caption,
    columnA,
    columnB,
    rows,
    totalLabel,
    totalA,
    totalB,
    footnote,
    calculatorLabel,
    calculatorHref,
    calculatorText,
  }) => {
    const H = headingLevel || "h2";
    const list = (rows ?? []).filter((r) => r?.item);
    const captionId = `${id || "tuition"}-caption`;
    const colA = columnA || "Rate A";
    const colB = columnB || "Rate B";
    const showPanel = Boolean(calculatorText || calculatorLabel);
    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">
          <div className="lg:col-span-4">
            {badge ? (
              <p className="inline-flex items-center gap-2 rounded-full bg-indigo-50 px-3 py-1 text-sm font-medium text-indigo-800 ring-1 ring-indigo-600/15 ring-inset">
                <span aria-hidden="true" className="size-1.5 rounded-full bg-indigo-600" />
                {badge}
              </p>
            ) : null}
            {heading ? (
              <H className={`text-3xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-4xl ${badge ? "mt-5" : ""}`}>{heading}</H>
            ) : null}
            {intro ? <p className="mt-4 text-base leading-7 text-pretty text-neutral-600">{intro}</p> : null}
            {showPanel ? (
              <div className="mt-8 rounded-2xl bg-neutral-950 p-6 sm:p-7">
                <svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" className="size-7 text-indigo-300">
                  <path strokeLinecap="round" strokeLinejoin="round" d="M15.75 15.75V18m-7.5-6.75h.008v.008H8.25v-.008Zm0 2.25h.008v.008H8.25V13.5Zm0 2.25h.008v.008H8.25v-.008Zm0 2.25h.008v.008H8.25V18Zm2.498-6.75h.007v.008h-.007v-.008Zm0 2.25h.007v.008h-.007V13.5Zm0 2.25h.007v.008h-.007v-.008Zm0 2.25h.007v.008h-.007V18Zm2.504-6.75h.008v.008h-.008v-.008Zm0 2.25h.008v.008h-.008V13.5Zm0 2.25h.008v.008h-.008v-.008Zm0 2.25h.008v.008h-.008V18Zm2.498-6.75h.008v.008h-.008v-.008Zm0 2.25h.008v.008h-.008V13.5ZM8.25 6h7.5v2.25h-7.5V6ZM12 2.25c-1.892 0-3.758.11-5.593.322C5.307 2.7 4.5 3.65 4.5 4.757V19.5a2.25 2.25 0 0 0 2.25 2.25h10.5a2.25 2.25 0 0 0 2.25-2.25V4.757c0-1.108-.806-2.057-1.907-2.185A48.507 48.507 0 0 0 12 2.25Z" />
                </svg>
                {calculatorText ? <p className="mt-4 text-base leading-7 text-pretty text-neutral-200">{calculatorText}</p> : null}
                {calculatorLabel ? (
                  <a
                    href={calculatorHref || "#"}
                    className="mt-5 inline-flex min-h-11 w-full items-center justify-center gap-1.5 rounded-lg bg-white px-5 py-3 text-base font-semibold text-neutral-950 transition hover:bg-indigo-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white sm:w-auto"
                  >
                    {calculatorLabel}
                    <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5">
                      <path fillRule="evenodd" d="M3 10a.75.75 0 0 1 .75-.75h10.64l-3.22-3.22a.75.75 0 1 1 1.06-1.06l4.5 4.5a.75.75 0 0 1 0 1.06l-4.5 4.5a.75.75 0 1 1-1.06-1.06l3.22-3.22H3.75A.75.75 0 0 1 3 10Z" clipRule="evenodd" />
                    </svg>
                  </a>
                ) : null}
              </div>
            ) : null}
          </div>
          <div className="lg:col-span-8">
            {list.length ? (
              <div
                role="region"
                aria-labelledby={captionId}
                tabIndex={0}
                className="-mx-4 relative overflow-x-auto px-4 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 sm:mx-0 sm:px-0"
              >
                <table className="w-full min-w-sm border-collapse text-left">
                  <caption id={captionId} className="pb-4 text-left text-sm font-medium text-neutral-600">
                    {caption || "Cost of attendance"}
                  </caption>
                  <thead>
                    <tr className="border-b-2 border-neutral-950">
                      <th scope="col" className="py-3 pr-4 text-sm font-semibold text-neutral-950">
                        <span className="sr-only">Cost item</span>
                      </th>
                      <th scope="col" className="py-3 pl-4 text-right text-sm font-semibold text-neutral-950">
                        {colA}
                      </th>
                      <th scope="col" className="py-3 pl-4 text-right text-sm font-semibold text-neutral-950">
                        {colB}
                      </th>
                    </tr>
                  </thead>
                  <tbody className="divide-y divide-neutral-200">
                    {list.map((row, i) => (
                      <tr key={`${row.item}-${i}`}>
                        <th scope="row" className="py-4 pr-4 text-base font-normal text-neutral-700">
                          {row.item}
                        </th>
                        <td className="py-4 pl-4 text-right text-base text-neutral-950 tabular-nums">{row.amountA || "—"}</td>
                        <td className="py-4 pl-4 text-right text-base text-neutral-950 tabular-nums">{row.amountB || "—"}</td>
                      </tr>
                    ))}
                  </tbody>
                  {totalLabel ? (
                    <tfoot>
                      <tr className="border-t-2 border-neutral-950">
                        <th scope="row" className="pt-5 pr-4 text-base font-semibold text-neutral-950">
                          {totalLabel}
                        </th>
                        <td className="pt-5 pl-4 text-right text-2xl font-semibold tracking-tight text-neutral-950 tabular-nums sm:text-3xl">
                          {totalA || sum(list, "amountA")}
                        </td>
                        <td className="pt-5 pl-4 text-right text-2xl font-semibold tracking-tight text-neutral-950 tabular-nums sm:text-3xl">
                          {totalB || sum(list, "amountB")}
                        </td>
                      </tr>
                    </tfoot>
                  ) : null}
                </table>
              </div>
            ) : null}
            {footnote ? <p className="mt-8 max-w-2xl text-sm leading-6 text-pretty text-neutral-600">{footnote}</p> : null}
          </div>
        </div>
      </section>
    );
  },
};
```
