# Add the "Pagination" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/pagination) to this Pantheon Content Publisher (P1) Next.js project. Previous, next and numbered page links with ellipses, built from the current page, page count and a URL pattern.

## Steps

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

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

/**
 * Pagination — previous/next links plus numbered pages with ellipses, built from the
 * current page, the page count and a URL pattern. Phones get a compact "Page 3 of 12".
 * Register: `PaginationBlock: paginationBlock` in puck.config.tsx.
 */

export type PaginationProps = {
  currentPage: number;
  totalPages: number;
  urlPattern: string;
  firstPageHref: string;
  siblings: "1" | "2";
  previousLabel: string;
  nextLabel: string;
  navLabel: string;
};

const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600";

function pageList(current: number, total: number, siblings: number): (number | "gap")[] {
  const keep = new Set<number>([1, total]);
  for (let p = current - siblings; p <= current + siblings; p++) if (p >= 1 && p <= total) keep.add(p);
  // Show a lone page instead of an ellipsis that would hide only one number.
  const sorted = [...keep].sort((a, b) => a - b);
  const out: (number | "gap")[] = [];
  sorted.forEach((p, i) => {
    const prev = sorted[i - 1];
    if (prev !== undefined && p - prev === 2) out.push(prev + 1);
    else if (prev !== undefined && p - prev > 2) out.push("gap");
    out.push(p);
  });
  return out;
}

export const paginationBlock: ComponentConfig<PaginationProps> = {
  label: "Pagination",
  fields: {
    currentPage: { type: "number", label: "Current page", min: 1 },
    totalPages: { type: "number", label: "Total pages", min: 1 },
    urlPattern: {
      type: "text",
      label: "Page URL pattern",
      metadata: { help: "Use {page} where the number goes, like /news?page={page} or /news/page/{page}." },
    },
    firstPageHref: {
      type: "text",
      label: "First page link",
      metadata: { help: "Optional. Many sites use the plain URL for page 1, like /news. Leave blank to use the pattern." },
    },
    siblings: {
      type: "radio",
      label: "Numbers around current",
      options: [
        { label: "1", value: "1" },
        { label: "2", value: "2" },
      ],
      metadata: { help: "How many page numbers show on each side of the current page on wider screens." },
    },
    previousLabel: { type: "text", label: "Previous text" },
    nextLabel: { type: "text", label: "Next text" },
    navLabel: { type: "text", label: "Navigation name", metadata: { help: "Read by screen readers, like News pages. Name each pagination on a page differently." } },
  },
  defaultProps: {
    currentPage: 4,
    totalPages: 12,
    urlPattern: "/news?page={page}",
    firstPageHref: "/news",
    siblings: "1",
    previousLabel: "Previous",
    nextLabel: "Next",
    navLabel: "News pages",
  },
  render: ({ currentPage, totalPages, urlPattern, firstPageHref, siblings, previousLabel, nextLabel, navLabel }) => {
    const total = Math.max(1, Math.floor(Number(totalPages) || 1));
    const current = Math.min(total, Math.max(1, Math.floor(Number(currentPage) || 1)));
    if (total < 2) return <></>;
    const pattern = urlPattern || "?page={page}";
    const href = (p: number) => (p === 1 && firstPageHref ? firstPageHref : pattern.includes("{page}") ? pattern.split("{page}").join(String(p)) : `${pattern}${p}`);
    const pages = pageList(current, total, siblings === "2" ? 2 : 1);
    const prevText = previousLabel || "Previous";
    const nextText = nextLabel || "Next";

    const edge = (dir: "prev" | "next") => {
      const target = dir === "prev" ? current - 1 : current + 1;
      const disabled = target < 1 || target > total;
      const icon =
        dir === "prev" ? (
          <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5 shrink-0">
            <path fillRule="evenodd" d="M11.78 5.22a.75.75 0 0 1 0 1.06L8.06 10l3.72 3.72a.75.75 0 1 1-1.06 1.06l-4.25-4.25a.75.75 0 0 1 0-1.06l4.25-4.25a.75.75 0 0 1 1.06 0Z" clipRule="evenodd" />
          </svg>
        ) : (
          <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5 shrink-0">
            <path fillRule="evenodd" d="M8.22 5.22a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.94 10 8.22 6.28a.75.75 0 0 1 0-1.06Z" clipRule="evenodd" />
          </svg>
        );
      const text = dir === "prev" ? prevText : nextText;
      const inner = dir === "prev" ? (
        <>
          {icon}
          <span>{text}</span>
        </>
      ) : (
        <>
          <span>{text}</span>
          {icon}
        </>
      );
      const shape = "inline-flex min-h-11 items-center gap-1.5 rounded-lg px-3 text-sm font-semibold";
      if (disabled) {
        return (
          <a aria-disabled="true" role="link" className={`${shape} cursor-not-allowed text-neutral-400`}>
            {inner}
          </a>
        );
      }
      return (
        <a href={href(target)} rel={dir} className={`${shape} text-neutral-800 ring-1 ring-neutral-300 transition ring-inset hover:bg-neutral-50 hover:text-neutral-950 ${focusRing}`}>
          {inner}
        </a>
      );
    };

    return (
      <nav aria-label={navLabel || "Pagination"} className="bg-white px-4 py-8 sm:px-6 lg:px-8">
        <div className="mx-auto flex max-w-7xl items-center justify-between gap-3 border-t border-neutral-200 pt-6">
          <div className="flex flex-1 justify-start">{edge("prev")}</div>
          <p className="text-sm text-neutral-600 tabular-nums sm:hidden">
            Page <span className="font-semibold text-neutral-950">{current}</span> of <span className="font-semibold text-neutral-950">{total}</span>
          </p>
          <ul role="list" className="hidden items-center gap-1 sm:flex">
            {pages.map((p, i) =>
              p === "gap" ? (
                <li key={`gap-${i}`} aria-hidden="true" className="inline-flex min-h-11 w-8 items-end justify-center pb-2 text-sm text-neutral-500">
                  &hellip;
                </li>
              ) : (
                <li key={p}>
                  <a
                    href={href(p)}
                    aria-current={p === current ? "page" : undefined}
                    className={`inline-flex min-h-11 min-w-11 items-center justify-center rounded-lg px-2 text-sm font-semibold tabular-nums transition ${focusRing} ${
                      p === current ? "bg-indigo-600 text-white shadow-sm" : "text-neutral-700 hover:bg-neutral-100 hover:text-neutral-950"
                    }`}
                  >
                    <span className="sr-only">Page </span>
                    {p}
                  </a>
                </li>
              ),
            )}
          </ul>
          <div className="flex flex-1 justify-end">{edge("next")}</div>
        </div>
      </nav>
    );
  },
};
```
