# Add the "Before/After Impact" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/before-after-impact) to this Pantheon Content Publisher (P1) Next.js project. Side-by-side before and after program figures with paired bars, a labeled change and a source line.

## Steps

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

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

/**
 * Before / After Impact — side-by-side "before our program" and "after" figures for each
 * outcome you track, with paired bars and a labeled change, plus a source line.
 * Register: `BeforeAfterImpactBlock: beforeAfterImpactBlock` in puck.config.tsx.
 */

type Heading = "h1" | "h2" | "h3" | "h4";
type Direction = "up" | "down" | "none";

export type BeforeAfterImpactProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  beforeLabel: string;
  afterLabel: string;
  changeLabel: string;
  metrics: { label: string; before: string; after: string; change: string; direction: Direction; note: string }[];
  cohort: string;
  source: string;
};

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

const toNumber = (v?: string) => {
  const n = parseFloat(String(v ?? "").replace(/[^0-9.-]/g, ""));
  return Number.isFinite(n) ? n : null;
};

const arrows: Record<Direction, string> = {
  up: "M10 17a.75.75 0 0 1-.75-.75V5.612L5.29 9.77a.75.75 0 0 1-1.08-1.04l5.25-5.5a.75.75 0 0 1 1.08 0l5.25 5.5a.75.75 0 1 1-1.08 1.04l-3.96-4.158V16.25A.75.75 0 0 1 10 17Z",
  down: "M10 3a.75.75 0 0 1 .75.75v10.638l3.96-4.158a.75.75 0 1 1 1.08 1.04l-5.25 5.5a.75.75 0 0 1-1.08 0l-5.25-5.5a.75.75 0 1 1 1.08-1.04l3.96 4.158V3.75A.75.75 0 0 1 10 3Z",
  none: "M4 10a.75.75 0 0 1 .75-.75h10.5a.75.75 0 0 1 0 1.5H4.75A.75.75 0 0 1 4 10Z",
};

export const beforeAfterImpactBlock: ComponentConfig<BeforeAfterImpactProps> = {
  label: "Before / After Impact",
  fields: {
    heading: { type: "textarea", 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" },
    beforeLabel: { type: "text", label: "Before label", metadata: { help: "Like Before the program or At intake." } },
    afterLabel: { type: "text", label: "After label", metadata: { help: "Like After 12 months or At graduation." } },
    changeLabel: { type: "text", label: "Change column label", metadata: { help: "Column heading on wide screens, like Change." } },
    metrics: {
      type: "array",
      label: "Outcomes",
      min: 1,
      max: 6,
      getItemSummary: (item) => (item?.label ? `${item.label}: ${item.before || "—"} → ${item.after || "—"}` : "Outcome"),
      defaultItemProps: { label: "New outcome", before: "40%", after: "60%", change: "+20 points", direction: "up", note: "" },
      arrayFields: {
        label: { type: "text", label: "Outcome", metadata: { help: "What you measured, like Families with stable housing." } },
        before: { type: "text", label: "Before", metadata: { help: "Like 34% or 2.1. Text so it can be bound to a data source." } },
        after: { type: "text", label: "After" },
        change: { type: "text", label: "Change label", metadata: { help: "Spell the change out, like +38 points or Down by half." } },
        direction: {
          type: "select",
          label: "Change direction",
          options: [
            { label: "Went up", value: "up" },
            { label: "Went down", value: "down" },
            { label: "No change", value: "none" },
          ],
          metadata: { help: "Sets the arrow. Whether that's good is up to the change label, so a drop in wait times reads as a win." },
        },
        note: { type: "text", label: "Note", metadata: { help: "Optional context, like Median, not average." } },
      },
    },
    cohort: { type: "text", label: "Who was measured", metadata: { help: "Like 212 families who completed the program in 2023–2025." } },
    source: { type: "text", label: "Source line", metadata: { help: "Where the numbers come from, like Source: 2025 independent evaluation." } },
  },
  defaultProps: {
    heading: "What changes when a family joins Pathways Home",
    headingLevel: "h2",
    intro: "We measure the same outcomes when a family enrolls and again a year later, so you can see the difference your support makes.",
    beforeLabel: "At enrollment",
    afterLabel: "After 12 months",
    changeLabel: "Change",
    metrics: [
      { label: "Families in stable housing", before: "18%", after: "86%", change: "+68 points", direction: "up", note: "" },
      { label: "Adults employed full-time", before: "31%", after: "64%", change: "+33 points", direction: "up", note: "" },
      { label: "Children attending school regularly", before: "57%", after: "92%", change: "+35 points", direction: "up", note: "Missing fewer than 10% of school days." },
      { label: "Share of income spent on rent", before: "71%", after: "38%", change: "Down 33 points", direction: "down", note: "Median, not average." },
    ],
    cohort: "Sample data: 212 families who enrolled between January 2023 and June 2024.",
    source: "Source: Pathways Home 2025 outcomes evaluation (sample figures).",
  },
  render: ({ heading, headingLevel, intro, beforeLabel, afterLabel, changeLabel, metrics, cohort, source }) => {
    const H = headingLevel || "h2";
    const Sub = childHeading[H] ?? "h3";
    const before = beforeLabel || "Before";
    const after = afterLabel || "After";
    const rows = (metrics ?? []).filter((m) => m?.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">
          <div className="max-w-2xl">
            {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}
          </div>

          {rows.length ? (
            <div className="mt-12 overflow-hidden rounded-2xl bg-white shadow-sm ring-1 ring-neutral-200 lg:mt-14">
              <div aria-hidden="true" className="hidden grid-cols-12 gap-6 border-b border-neutral-200 bg-neutral-50/60 px-8 py-4 text-sm font-semibold text-neutral-600 md:grid">
                <span className="col-span-4" />
                <span className="col-span-3 flex items-center gap-2">
                  <span className="size-2.5 rounded-sm bg-neutral-400" />
                  {before}
                </span>
                <span className="col-span-3 flex items-center gap-2 text-indigo-700">
                  <span className="size-2.5 rounded-sm bg-indigo-600" />
                  {after}
                </span>
                <span className="col-span-2 text-right">{changeLabel}</span>
              </div>

              <ul role="list" className="divide-y divide-neutral-200">
                {rows.map((m, i) => {
                  const dir: Direction = m.direction && arrows[m.direction] ? m.direction : "none";
                  const b = toNumber(m.before);
                  const a = toNumber(m.after);
                  const max = b !== null && a !== null ? Math.max(Math.abs(b), Math.abs(a)) : 0;
                  const bars = max > 0 && b !== null && a !== null;
                  const bw = bars ? Math.max(2, (Math.abs(b) / max) * 100) : 0;
                  const aw = bars ? Math.max(2, (Math.abs(a) / max) * 100) : 0;
                  return (
                    <li key={`${m.label}-${i}`} className="grid grid-cols-1 gap-5 px-5 py-6 sm:px-8 md:grid-cols-12 md:items-center md:gap-6">
                      <div className="md:col-span-4">
                        <Sub className="text-base font-semibold text-neutral-950">{m.label}</Sub>
                        {m.note ? <p className="mt-1 text-sm text-neutral-600">{m.note}</p> : null}
                      </div>

                      <dl className="grid grid-cols-2 gap-4 md:col-span-6 md:gap-6">
                        <div>
                          <dt className="text-xs font-medium text-neutral-600 md:sr-only">{before}</dt>
                          <dd className="mt-1 md:mt-0">
                            <span className="text-2xl font-semibold tracking-tight text-neutral-600 tabular-nums sm:text-3xl">{m.before || "—"}</span>
                            {bars ? (
                              <span aria-hidden="true" className="mt-2 block h-2 rounded-full bg-neutral-100">
                                <span className="block h-full rounded-full bg-neutral-400" style={{ width: `${bw}%` }} />
                              </span>
                            ) : null}
                          </dd>
                        </div>
                        <div>
                          <dt className="text-xs font-medium text-indigo-700 md:sr-only">{after}</dt>
                          <dd className="mt-1 md:mt-0">
                            <span className="text-2xl font-semibold tracking-tight text-neutral-950 tabular-nums sm:text-3xl">{m.after || "—"}</span>
                            {bars ? (
                              <span aria-hidden="true" className="mt-2 block h-2 rounded-full bg-indigo-50">
                                <span className="block h-full rounded-full bg-indigo-600" style={{ width: `${aw}%` }} />
                              </span>
                            ) : null}
                          </dd>
                        </div>
                      </dl>

                      {m.change ? (
                        <p className="md:col-span-2 md:text-right">
                          <span className="inline-flex items-center gap-1 rounded-full bg-indigo-50 px-2.5 py-1 text-sm font-semibold text-indigo-800 ring-1 ring-indigo-600/20 ring-inset tabular-nums">
                            <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 shrink-0">
                              <path fillRule="evenodd" d={arrows[dir]} clipRule="evenodd" />
                            </svg>
                            <span className="sr-only">{changeLabel || "Change"}: </span>
                            {m.change}
                          </span>
                        </p>
                      ) : null}
                    </li>
                  );
                })}
              </ul>
            </div>
          ) : null}

          {cohort || source ? (
            <div className="mt-5 space-y-1 text-sm text-neutral-600">
              {cohort ? <p>{cohort}</p> : null}
              {source ? <p>{source}</p> : null}
            </div>
          ) : null}
        </div>
      </section>
    );
  },
};
```
