# Add the "Achievement Data" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/achievement-data) to this Pantheon Content Publisher (P1) Next.js project. Graduation, attendance and subject proficiency as labeled bars compared with district and state, with a table view and source.

## Steps

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

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

/**
 * Achievement Data — a school performance snapshot: headline rates (graduation, attendance)
 * and proficiency by subject as labeled bars, each compared with district and state as text.
 * Register: `AchievementDataBlock: achievementDataBlock` in puck.config.tsx.
 */

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

type Row = { label: string; school: string; district: string; state: string };

export type AchievementDataProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  schoolLabel: string;
  highlights: Row[];
  subjectsHeading: string;
  subjects: Row[];
  source: string;
  reportLabel: string;
  reportHref: string;
};

const lower = { h1: "h2", h2: "h3", h3: "h4", h4: "h5" } as const;

function pct(raw?: string) {
  const n = parseFloat(String(raw ?? "").replace(/[^\d.-]/g, ""));
  return Number.isFinite(n) ? Math.min(100, Math.max(0, n)) : null;
}
const show = (n: number | null) => (n === null ? "—" : `${Math.round(n * 10) / 10}%`);

function diff(a: number | null, b: number | null, name: string) {
  if (a === null || b === null) return null;
  const d = Math.round((a - b) * 10) / 10;
  if (d === 0) return `Same as ${name}`;
  return `${Math.abs(d)} points ${d > 0 ? "above" : "below"} ${name}`;
}

const series = [
  { key: "school", bar: "bg-indigo-600", text: "font-semibold text-neutral-950" },
  { key: "district", bar: "bg-indigo-300", text: "text-neutral-700" },
  { key: "state", bar: "bg-neutral-400", text: "text-neutral-700" },
] as const;

export const achievementDataBlock: ComponentConfig<AchievementDataProps> = {
  label: "Achievement Data",
  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", metadata: { help: "Leave blank to hide it." } },
    schoolLabel: { type: "text", label: "School name (short)", metadata: { help: "Used in bar labels, like \"Riverbend High\". Leave blank to use \"This school\"." } },
    highlights: {
      type: "array",
      label: "Headline rates",
      min: 0,
      max: 4,
      getItemSummary: (item) => (item?.label ? `${item.label}: ${item.school || "—"}` : "Rate"),
      defaultItemProps: { label: "New rate", school: "", district: "", state: "" },
      arrayFields: {
        label: { type: "text", label: "Measure", metadata: { help: "Like \"Four-year graduation rate\"." } },
        school: { type: "text", label: "School %", metadata: { help: "A percentage, like 91 or 91%." } },
        district: { type: "text", label: "District %", metadata: { help: "Leave blank to hide it." } },
        state: { type: "text", label: "State %", metadata: { help: "Leave blank to hide it." } },
      },
    },
    subjectsHeading: { type: "text", label: "Subjects heading", metadata: { help: "Leave blank to use \"Students meeting grade-level standards\"." } },
    subjects: {
      type: "array",
      label: "Subjects",
      min: 0,
      max: 8,
      getItemSummary: (item) => (item?.label ? `${item.label}: ${item.school || "—"}` : "Subject"),
      defaultItemProps: { label: "New subject", school: "", district: "", state: "" },
      arrayFields: {
        label: { type: "text", label: "Subject" },
        school: { type: "text", label: "School %", metadata: { help: "Percent of students proficient, like 58." } },
        district: { type: "text", label: "District %" },
        state: { type: "text", label: "State %" },
      },
    },
    source: { type: "textarea", label: "Source", metadata: { help: "Where the numbers come from and which year. Required for trust; leave it visible." } },
    reportLabel: { type: "text", label: "Full report link text", metadata: { help: "Leave blank to hide it." } },
    reportHref: { type: "text", label: "Full report link" },
  },
  defaultProps: {
    heading: "How Riverbend High is doing",
    headingLevel: "h2",
    intro: "A quick look at graduation, attendance and test results, side by side with the district and the state.",
    schoolLabel: "Riverbend High",
    highlights: [
      { label: "Four-year graduation rate", school: "91", district: "88", state: "86" },
      { label: "Average daily attendance", school: "94", district: "93", state: "92" },
      { label: "Seniors completing a college or career pathway", school: "62", district: "55", state: "49" },
    ],
    subjectsHeading: "Students meeting grade-level standards",
    subjects: [
      { label: "English language arts", school: "58", district: "54", state: "49" },
      { label: "Math", school: "41", district: "39", state: "37" },
      { label: "Science", school: "47", district: "45", state: "44" },
    ],
    source: "Source: State Department of Education, 2025 school report card. Sample data for illustration.",
    reportLabel: "See the full school report card",
    reportHref: "/schools/riverbend-high/report-card",
  },
  render: ({ id, heading, headingLevel, intro, schoolLabel, highlights, subjectsHeading, subjects, source, reportLabel, reportHref }) => {
    const H = headingLevel || "h2";
    const Sub = lower[H] || "h3";
    const uid = id || "achievement-data";
    const name = schoolLabel || "This school";
    const names = { school: name, district: "District", state: "State" } as const;
    const stats = (highlights ?? []).filter((h) => h?.label);
    const rows = (subjects ?? []).filter((s) => s?.label);

    return (
      <section aria-labelledby={heading ? `${uid}-heading` : undefined} 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}-heading`} 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}

          {stats.length ? (
            <dl className={`grid grid-cols-1 gap-px overflow-hidden rounded-2xl bg-neutral-200 ring-1 ring-neutral-200 sm:grid-cols-2 lg:grid-cols-3 ${heading || intro ? "mt-10" : ""}`}>
              {stats.map((s, i) => {
                const v = pct(s.school);
                const d = pct(s.district);
                const st = pct(s.state);
                const vsDistrict = diff(v, d, "the district");
                return (
                  <div key={`${s.label}-${i}`} className="flex flex-col bg-white p-6 sm:p-7">
                    <dt className="text-sm leading-6 font-medium text-pretty text-neutral-600">{s.label}</dt>
                    <dd className="order-first text-4xl font-semibold tracking-tight text-neutral-950 tabular-nums sm:text-5xl">{show(v)}</dd>
                    {d !== null || st !== null ? (
                      <dd className="mt-3 flex flex-wrap gap-x-4 gap-y-1 border-t border-neutral-100 pt-3 text-sm text-neutral-700 tabular-nums">
                        {d !== null ? (
                          <span>
                            District <span className="font-semibold text-neutral-950">{show(d)}</span>
                          </span>
                        ) : null}
                        {st !== null ? (
                          <span>
                            State <span className="font-semibold text-neutral-950">{show(st)}</span>
                          </span>
                        ) : null}
                      </dd>
                    ) : null}
                    {vsDistrict ? <dd className="mt-1 text-xs leading-5 text-neutral-500">{vsDistrict}</dd> : null}
                  </div>
                );
              })}
            </dl>
          ) : null}

          {rows.length ? (
            <div className={stats.length || heading || intro ? "mt-14" : ""}>
              <div className="flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
                <Sub className="text-xl font-semibold tracking-tight text-neutral-950">{subjectsHeading || "Students meeting grade-level standards"}</Sub>
                <ul role="list" aria-label="Legend" className="flex flex-wrap gap-x-5 gap-y-1 text-sm text-neutral-700">
                  {series.map((s) => (
                    <li key={s.key} className="flex items-center gap-2">
                      <span aria-hidden="true" className={`h-2.5 w-5 rounded-full ${s.bar}`} />
                      {names[s.key]}
                    </li>
                  ))}
                </ul>
              </div>
              <ul role="list" className="mt-6 grid grid-cols-1 gap-x-12 gap-y-8 md:grid-cols-2">
                {rows.map((r, i) => {
                  const values = { school: pct(r.school), district: pct(r.district), state: pct(r.state) };
                  return (
                    <li key={`${r.label}-${i}`} className="min-w-0">
                      <p className="text-base font-semibold text-neutral-950">{r.label}</p>
                      <dl className="mt-3 space-y-2.5">
                        {series.map((s) => {
                          const v = values[s.key];
                          if (v === null && s.key !== "school") return null;
                          return (
                            <div key={s.key} className="grid grid-cols-1 gap-1 sm:grid-cols-12 sm:items-center sm:gap-3">
                              <dt className={`text-sm sm:col-span-3 ${s.text}`}>{names[s.key]}</dt>
                              <dd className="flex items-center gap-3 sm:col-span-9">
                                <span aria-hidden="true" className="h-3 flex-1 overflow-hidden rounded-full bg-neutral-100">
                                  <span className={`block h-full rounded-full ${s.bar}`} style={{ width: `${v ?? 0}%` }} />
                                </span>
                                <span className={`w-12 shrink-0 text-right text-sm tabular-nums ${s.text}`}>{show(v)}</span>
                              </dd>
                            </div>
                          );
                        })}
                      </dl>
                    </li>
                  );
                })}
              </ul>

              <details className="group mt-8 rounded-xl ring-1 ring-neutral-200">
                <summary className="flex min-h-11 cursor-pointer list-none items-center justify-between gap-3 rounded-xl px-4 text-sm font-semibold text-neutral-900 hover:bg-neutral-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-700 [&::-webkit-details-marker]:hidden">
                  View as a table
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5 shrink-0 text-neutral-500 transition group-open:rotate-180">
                    <path fillRule="evenodd" d="M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z" clipRule="evenodd" />
                  </svg>
                </summary>
                <div className="relative overflow-x-auto border-t border-neutral-200">
                  <table className="w-full min-w-80 text-left text-sm">
                    <caption className="sr-only">
                      {subjectsHeading || "Students meeting grade-level standards"}: {name}, district and state, in percent
                    </caption>
                    <thead className="bg-neutral-50 text-neutral-700">
                      <tr>
                        <th scope="col" className="px-4 py-3 font-semibold">Subject</th>
                        <th scope="col" className="px-4 py-3 text-right font-semibold">{name}</th>
                        <th scope="col" className="px-4 py-3 text-right font-semibold">District</th>
                        <th scope="col" className="px-4 py-3 text-right font-semibold">State</th>
                      </tr>
                    </thead>
                    <tbody className="divide-y divide-neutral-200 tabular-nums">
                      {rows.map((r, i) => (
                        <tr key={`${r.label}-${i}`}>
                          <th scope="row" className="px-4 py-3 font-medium text-neutral-950">{r.label}</th>
                          <td className="px-4 py-3 text-right text-neutral-950">{show(pct(r.school))}</td>
                          <td className="px-4 py-3 text-right text-neutral-700">{show(pct(r.district))}</td>
                          <td className="px-4 py-3 text-right text-neutral-700">{show(pct(r.state))}</td>
                        </tr>
                      ))}
                    </tbody>
                  </table>
                </div>
              </details>
            </div>
          ) : null}

          {source || reportLabel ? (
            <div className="mt-10 flex flex-col gap-3 border-t border-neutral-200 pt-6 sm:flex-row sm:items-center sm:justify-between sm:gap-8">
              {source ? <p className="text-sm leading-6 text-pretty text-neutral-600">{source}</p> : null}
              {reportLabel ? (
                <a
                  href={reportHref || "#"}
                  className="group inline-flex min-h-11 shrink-0 items-center gap-1.5 self-start rounded-md text-sm font-semibold text-indigo-700 hover:text-indigo-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-700 sm:self-auto"
                >
                  {reportLabel}
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 shrink-0 transition motion-safe:group-hover:translate-x-0.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>
      </section>
    );
  },
};
```
