# Add the "Preference Center" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/preference-center) to this Pantheon Content Publisher (P1) Next.js project. Email preference center with list checkboxes and cadence tags, a frequency choice and an unsubscribe-all option.

## Steps

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

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

/**
 * Preference Center — let subscribers choose which lists they get and how often, instead of
 * unsubscribing from everything. Topic checkboxes, frequency radios, and an unsubscribe-all option.
 * Register: `PreferenceCenterBlock: preferenceCenterBlock` in puck.config.tsx.
 */

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

type Topic = { name: string; description: string; cadence: string; checked: boolean };

export type PreferenceCenterProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  formAction: string;
  showEmailField: boolean;
  topics: Topic[];
  frequencies: { label: string }[];
  submitLabel: string;
  unsubscribeLabel: string;
  unsubscribeHelp: string;
  footnote: string;
};

const inputClass =
  "block min-h-11 w-full rounded-lg border-0 bg-white px-3.5 py-2.5 text-base text-neutral-950 shadow-xs ring-1 ring-neutral-300 ring-inset placeholder:text-neutral-500 focus:ring-2 focus:ring-indigo-600 focus:outline-none";
const legendClass = "text-base leading-7 font-semibold text-neutral-950";

export const preferenceCenterBlock: ComponentConfig<PreferenceCenterProps> = {
  label: "Preference Center",
  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" },
    formAction: {
      type: "text",
      label: "Form action URL",
      metadata: {
        help: "Your email platform's preference endpoint. Sent with POST: email, topics (one value per checked list), frequency and unsubscribe_all. Most platforms also need a subscriber token in the URL.",
      },
    },
    showEmailField: {
      type: "radio",
      label: "Ask for email",
      options: [
        { label: "Yes", value: true },
        { label: "No", value: false },
      ],
      metadata: { help: "Turn off when the page is reached from a personalized email link that already identifies the subscriber." },
    },
    topics: {
      type: "array",
      label: "Lists",
      min: 1,
      max: 10,
      getItemSummary: (item) => `${item?.name || "List"}${item?.checked ? " (on)" : ""}`,
      defaultItemProps: { name: "New list", description: "", cadence: "Monthly", checked: false },
      arrayFields: {
        name: { type: "text", label: "Name" },
        description: { type: "textarea", label: "What's in it" },
        cadence: { type: "text", label: "How often", metadata: { help: "Shown as a small tag, such as Weekly or 4 times a year." } },
        checked: {
          type: "radio",
          label: "Checked at first",
          options: [
            { label: "Yes", value: true },
            { label: "No", value: false },
          ],
          metadata: { help: "When your platform fills in the subscriber's current choices, leave these off." },
        },
      },
    },
    frequencies: {
      type: "array",
      label: "Frequency options",
      min: 0,
      max: 4,
      getItemSummary: (item) => item?.label || "Option",
      defaultItemProps: { label: "Monthly digest" },
      arrayFields: { label: { type: "text", label: "Option" } },
      metadata: { help: "The first option is selected at first. Leave empty to hide the question." },
    },
    submitLabel: { type: "text", label: "Save button text" },
    unsubscribeLabel: { type: "text", label: "Unsubscribe option", metadata: { help: "Checkbox text for leaving every list. Leave blank to hide it." } },
    unsubscribeHelp: { type: "text", label: "Unsubscribe help" },
    footnote: { type: "textarea", label: "Footnote", metadata: { help: "Small print, such as a note about transactional emails. Leave blank to hide it." } },
  },
  defaultProps: {
    heading: "Choose what lands in your inbox",
    headingLevel: "h2",
    intro: "Hear about the things you care about and skip the rest. Change these any time from the link at the bottom of every email.",
    formAction: "/email/preferences",
    showEmailField: true,
    topics: [
      { name: "The Riverbend Dispatch", description: "Stories from the parks, trail updates and what's blooming, with one easy way to help.", cadence: "Monthly", checked: true },
      { name: "Volunteer calls", description: "Workdays, cleanups and planting events near you, sent when sign-ups open.", cadence: "2–3 a month", checked: false },
      { name: "Family programs", description: "Camps, nature walks and storytimes for kids, sent before registration opens.", cadence: "Seasonal", checked: false },
      { name: "Advocacy alerts", description: "Council votes and public comment periods that affect parks funding.", cadence: "As needed", checked: false },
    ],
    frequencies: [{ label: "Everything I picked, as it's sent" }, { label: "One monthly roundup" }],
    submitLabel: "Save my preferences",
    unsubscribeLabel: "Unsubscribe me from all lists",
    unsubscribeHelp: "Overrides the choices above.",
    footnote: "You'll still receive receipts for gifts and registrations, because those are about your account, not marketing.",
  },
  render: ({ id, heading, headingLevel, intro, formAction, showEmailField, topics, frequencies, submitLabel, unsubscribeLabel, unsubscribeHelp, footnote }) => {
    const H = headingLevel || "h2";
    const uid = `pc-${id || "prefs"}`;
    const list = (topics ?? []).filter((t) => t?.name);
    const freq = (frequencies ?? []).map((f) => f?.label?.trim()).filter(Boolean) as string[];

    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-3xl">
          {heading ? <H 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}

          <form action={formAction || undefined} method="post" className={`rounded-2xl bg-white shadow-sm ring-1 ring-neutral-200 ${heading || intro ? "mt-10" : ""}`}>
            {showEmailField !== false ? (
              <div className="border-b border-neutral-200 p-6 sm:p-8">
                <label htmlFor={`${uid}-email`} className="block text-sm leading-6 font-medium text-neutral-900">
                  Your email
                </label>
                <input
                  id={`${uid}-email`}
                  name="email"
                  type="email"
                  required
                  autoComplete="email"
                  inputMode="email"
                  aria-describedby={`${uid}-email-hint`}
                  className={`mt-2 sm:max-w-md ${inputClass}`}
                />
                <p id={`${uid}-email-hint`} className="mt-2 text-sm leading-6 text-neutral-600">
                  Required, so we know whose preferences to update.
                </p>
              </div>
            ) : null}

            {list.length ? (
              <fieldset className="p-6 sm:p-8">
                <legend className={`${legendClass} float-left w-full`}>Lists</legend>
                <ul role="list" className="clear-both divide-y divide-neutral-200 pt-2">
                  {list.map((t, i) => {
                    const inputId = `${uid}-topic-${i}`;
                    return (
                      <li key={`${t.name}-${i}`} className="py-4">
                        <div className="flex gap-4">
                          <div className="flex h-11 shrink-0 items-center">
                            <input
                              id={inputId}
                              name="topics"
                              type="checkbox"
                              value={t.name}
                              defaultChecked={Boolean(t.checked)}
                              aria-describedby={t.description ? `${inputId}-desc` : undefined}
                              className="size-5 rounded border-neutral-400 accent-indigo-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                            />
                          </div>
                          <div className="min-w-0 flex-1">
                            <div className="flex min-h-11 flex-wrap items-center gap-x-3 gap-y-1">
                              <label htmlFor={inputId} className="cursor-pointer text-base leading-7 font-medium text-neutral-950">
                                {t.name}
                              </label>
                              {t.cadence ? (
                                <span className="rounded-full bg-neutral-100 px-2.5 py-0.5 text-xs leading-5 font-medium text-neutral-700 ring-1 ring-neutral-200 ring-inset">{t.cadence}</span>
                              ) : null}
                            </div>
                            {t.description ? (
                              <p id={`${inputId}-desc`} className="text-sm leading-6 text-pretty text-neutral-600">
                                {t.description}
                              </p>
                            ) : null}
                          </div>
                        </div>
                      </li>
                    );
                  })}
                </ul>
              </fieldset>
            ) : null}

            {freq.length ? (
              <fieldset className="border-t border-neutral-200 p-6 sm:p-8">
                <legend className={`${legendClass} float-left w-full`}>How often should we write?</legend>
                <div className="clear-both grid grid-cols-1 gap-3 pt-4 sm:grid-cols-2">
                  {freq.map((f, i) => (
                    <label
                      key={`${f}-${i}`}
                      className="flex min-h-14 cursor-pointer items-center gap-3 rounded-xl px-4 py-3 text-sm leading-6 font-medium text-neutral-900 ring-1 ring-neutral-300 transition select-none ring-inset hover:ring-indigo-400 has-checked:bg-indigo-50 has-checked:ring-2 has-checked:ring-indigo-600 has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-indigo-600"
                    >
                      <input type="radio" name="frequency" value={f} defaultChecked={i === 0} className="size-4 shrink-0 accent-indigo-600 focus:outline-none" />
                      {f}
                    </label>
                  ))}
                </div>
              </fieldset>
            ) : null}

            <div className="flex flex-col gap-6 rounded-b-2xl border-t border-neutral-200 bg-neutral-50 p-6 sm:p-8 md:flex-row md:items-center md:justify-between">
              {unsubscribeLabel ? (
                <div className="flex gap-3">
                  <div className="flex h-11 shrink-0 items-center">
                    <input
                      id={`${uid}-unsub`}
                      name="unsubscribe_all"
                      type="checkbox"
                      value="yes"
                      aria-describedby={unsubscribeHelp ? `${uid}-unsub-hint` : undefined}
                      className="size-5 rounded border-neutral-400 accent-indigo-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                    />
                  </div>
                  <div className="flex min-h-11 flex-col justify-center text-sm leading-6">
                    <label htmlFor={`${uid}-unsub`} className="cursor-pointer font-medium text-neutral-900">
                      {unsubscribeLabel}
                    </label>
                    {unsubscribeHelp ? (
                      <span id={`${uid}-unsub-hint`} className="text-neutral-600">
                        {unsubscribeHelp}
                      </span>
                    ) : null}
                  </div>
                </div>
              ) : null}
              <button
                type="submit"
                className="inline-flex min-h-11 shrink-0 items-center justify-center 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 md:ml-auto"
              >
                {submitLabel || "Save preferences"}
              </button>
            </div>
          </form>
          {footnote ? <p className="mt-6 text-sm leading-6 text-pretty text-neutral-600">{footnote}</p> : null}
        </div>
      </section>
    );
  },
};
```
