# Add the "Search Results" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/search-results) to this Pantheon Content Publisher (P1) Next.js project. Search box, result count and results with type badges and highlighted matches, plus a helpful no-results state.

## Steps

1. Create `components/puck/search-results-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 { searchResultsBlock } from "./components/puck/search-results-block";`
3. Register it under `components` as `SearchResultsBlock: searchResultsBlock`.
4. Add `"SearchResultsBlock"` 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/search-results-block.tsx`

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

/**
 * Search Results — a search box, a result count and a list of results with type badges and
 * highlighted matches. With no results it shows a friendly empty state with suggestions.
 * Register: `SearchResultsBlock: searchResultsBlock` in puck.config.tsx.
 */

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

export type SearchResultsProps = {
  heading: string;
  headingLevel: Heading;
  query: string;
  formAction: string;
  queryParam: string;
  searchLabel: string;
  buttonLabel: string;
  totalResults: string;
  results: { title: string; url: string; excerpt: string; type: string; date: string }[];
  preview: "auto" | "empty";
  emptyHeading: string;
  emptyBody: string;
  suggestions: { label: string; href: string }[];
};

const childLevel = { h1: "h2", h2: "h3", h3: "h4", h4: "h5" } as const;
const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600";

function highlight(text: string, query: string) {
  const words = (query || "")
    .split(/\s+/)
    .map((w) => w.trim())
    .filter((w) => w.length > 2)
    .map((w) => w.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
  if (!words.length || !text) return text;
  const re = new RegExp(`(${words.join("|")})`, "gi");
  return text.split(re).map((part, i) =>
    i % 2 === 1 ? (
      <mark key={i} className="rounded-sm bg-indigo-100 px-0.5 font-semibold text-neutral-950">
        {part}
      </mark>
    ) : (
      part
    ),
  );
}

export const searchResultsBlock: ComponentConfig<SearchResultsProps> = {
  label: "Search Results",
  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." },
    },
    query: { type: "text", label: "Search terms", metadata: { help: "What the visitor searched for. Shown above the results and prefilled in the search box." } },
    formAction: { type: "text", label: "Search page URL", metadata: { help: "Where the search box sends people, like /search." } },
    queryParam: { type: "text", label: "Search parameter name", metadata: { help: "The URL name for the search terms, usually q." } },
    searchLabel: { type: "text", label: "Search box label" },
    buttonLabel: { type: "text", label: "Button text" },
    totalResults: {
      type: "text",
      label: "Total results",
      metadata: { help: "Optional. The full count when results span several pages. Leave blank to count the results listed below." },
    },
    results: {
      type: "array",
      label: "Results",
      min: 0,
      max: 50,
      getItemSummary: (item) => item?.title || "Result",
      defaultItemProps: { title: "New result", url: "/", excerpt: "", type: "Page", date: "" },
      arrayFields: {
        title: { type: "text", label: "Title" },
        url: { type: "text", label: "Link" },
        excerpt: { type: "textarea", label: "Excerpt", metadata: { help: "A sentence or two from the page. Search words are highlighted automatically." } },
        type: { type: "text", label: "Type badge", metadata: { help: "Like Page, Event, Program, Document or News. Leave blank to hide it." } },
        date: { type: "text", label: "Date", metadata: { help: "Free text, like Updated Sep 30, 2026. Leave blank to hide it." } },
      },
    },
    preview: {
      type: "radio",
      label: "Show",
      options: [
        { label: "Results", value: "auto" },
        { label: "No results", value: "empty" },
      ],
      metadata: { help: "Preview the no-results message. It also shows automatically whenever the results list is empty." },
    },
    emptyHeading: { type: "text", label: "No-results heading" },
    emptyBody: { type: "textarea", label: "No-results text" },
    suggestions: {
      type: "array",
      label: "Suggested links",
      min: 0,
      max: 8,
      getItemSummary: (item) => item?.label || "Link",
      defaultItemProps: { label: "New link", href: "/" },
      arrayFields: {
        label: { type: "text", label: "Label" },
        href: { type: "text", label: "Link" },
      },
      metadata: { help: "Popular pages offered when nothing matches." },
    },
  },
  defaultProps: {
    heading: "Search",
    headingLevel: "h1",
    query: "summer camp",
    formAction: "/search",
    queryParam: "q",
    searchLabel: "Search the site",
    buttonLabel: "Search",
    totalResults: "",
    results: [
      {
        title: "Summer Day Camp 2027",
        url: "/programs/summer-day-camp",
        excerpt: "Eight weeks of swimming, nature hikes and arts for ages 6–12 at four community centers. Summer camp registration opens February 1 for residents.",
        type: "Program",
        date: "Updated Sep 30, 2026",
      },
      {
        title: "Camp financial aid application",
        url: "/programs/aid",
        excerpt: "Households that qualify can receive up to 75% off summer camp fees. Apply once and it covers every program for the year.",
        type: "Document",
        date: "Updated Aug 12, 2026",
      },
      {
        title: "Counselor jobs: now hiring for summer",
        url: "/jobs/camp-counselor",
        excerpt: "Seasonal camp counselor roles for ages 16 and up. Paid training, flexible weeks, and lifeguard certification at no cost.",
        type: "News",
        date: "Sep 18, 2026",
      },
      {
        title: "Adaptive recreation",
        url: "/programs/adaptive",
        excerpt: "Inclusive programs and one-on-one support so every camper can join in, including sensory-friendly summer sessions.",
        type: "Page",
        date: "",
      },
    ],
    preview: "auto",
    emptyHeading: "No results found",
    emptyBody: "Check the spelling, try fewer or more general words, or start from one of these popular pages.",
    suggestions: [
      { label: "Programs & classes", href: "/programs" },
      { label: "Find a park", href: "/parks" },
      { label: "Events calendar", href: "/events" },
      { label: "Contact us", href: "/contact" },
    ],
  },
  render: ({ id, heading, headingLevel, query, formAction, queryParam, searchLabel, buttonLabel, totalResults, results, preview, emptyHeading, emptyBody, suggestions }) => {
    const H = headingLevel || "h1";
    const Sub = childLevel[H] ?? "h2";
    const list = preview === "empty" ? [] : (results ?? []).filter((r) => r?.title);
    const links = (suggestions ?? []).filter((s) => s?.label);
    const countDigits = (totalResults || "").replace(/[^\d]/g, "");
    const count = countDigits ? Number(countDigits) : list.length;
    const q = (query || "").trim();
    const inputId = `search-${id}`;

    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 max-w-3xl">
          {heading ? <H className="text-3xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-4xl">{heading}</H> : null}

          <form role="search" action={formAction || undefined} method="get" className={`flex flex-col gap-3 sm:flex-row ${heading ? "mt-8" : ""}`}>
            <label htmlFor={inputId} className="sr-only">
              {searchLabel || "Search the site"}
            </label>
            <div className="relative min-w-0 flex-1">
              <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="pointer-events-none absolute top-1/2 left-4 size-5 -translate-y-1/2 text-neutral-500">
                <path fillRule="evenodd" d="M9 3.5a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11ZM2 9a7 7 0 1 1 12.452 4.391l3.328 3.329a.75.75 0 1 1-1.06 1.06l-3.329-3.328A7 7 0 0 1 2 9Z" clipRule="evenodd" />
              </svg>
              <input
                id={inputId}
                type="search"
                name={queryParam || "q"}
                defaultValue={q}
                className="block min-h-12 w-full rounded-lg border-0 bg-white py-3 pr-4 pl-11 text-base text-neutral-950 shadow-sm ring-1 ring-neutral-300 ring-inset placeholder:text-neutral-500 focus:ring-2 focus:ring-indigo-600 focus:outline-none"
              />
            </div>
            <button
              type="submit"
              className={`inline-flex min-h-12 shrink-0 items-center justify-center rounded-lg bg-indigo-600 px-6 py-3 text-base font-semibold text-white shadow-sm transition hover:bg-indigo-700 ${focusRing}`}
            >
              {buttonLabel || "Search"}
            </button>
          </form>

          {list.length ? (
            <>
              <p className="mt-8 border-b border-neutral-200 pb-4 text-sm text-neutral-600">
                <span className="font-semibold text-neutral-950 tabular-nums">{count.toLocaleString("en-US")}</span> {count === 1 ? "result" : "results"}
                {q ? (
                  <>
                    {" "}for <span className="font-semibold text-neutral-950">&ldquo;{q}&rdquo;</span>
                  </>
                ) : null}
              </p>
              <ol role="list" className="divide-y divide-neutral-200">
                {list.map((r, i) => (
                  <li key={`${r.title}-${i}`} className="group relative py-6">
                    <div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-sm">
                      {r.type ? (
                        <span className="inline-flex items-center rounded-md bg-indigo-50 px-2 py-0.5 text-xs font-semibold text-indigo-800 ring-1 ring-indigo-600/20 ring-inset">
                          {r.type}
                        </span>
                      ) : null}
                      {r.date ? <span className="text-neutral-600">{r.date}</span> : null}
                    </div>
                    <Sub className="mt-2 text-lg font-semibold text-pretty text-neutral-950">
                      <a
                        href={r.url || "#"}
                        className="rounded-sm underline decoration-transparent underline-offset-4 outline-none transition group-hover:decoration-indigo-600 after:absolute after:inset-0 focus-visible:after:rounded-xl focus-visible:after:outline-2 focus-visible:after:outline-offset-2 focus-visible:after:outline-indigo-600"
                      >
                        {r.title}
                      </a>
                    </Sub>
                    {r.url ? <p className="mt-1 truncate text-sm text-indigo-700">{r.url}</p> : null}
                    {r.excerpt ? <p className="mt-2 text-base leading-7 text-pretty text-neutral-600">{highlight(r.excerpt, q)}</p> : null}
                  </li>
                ))}
              </ol>
            </>
          ) : (
            <div className="mt-10 rounded-2xl border border-dashed border-neutral-300 px-6 py-10 text-center sm:px-10">
              <span aria-hidden="true" className="mx-auto grid size-12 place-items-center rounded-full bg-neutral-100 text-neutral-500">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" className="size-6">
                  <circle cx="10.5" cy="10.5" r="6.5" />
                  <path strokeLinecap="round" d="m20 20-4.5-4.5M8.5 10.5h4" />
                </svg>
              </span>
              <Sub className="mt-4 text-lg font-semibold text-neutral-950">
                {emptyHeading || "No results found"}
                {q ? (
                  <span className="block text-base font-normal text-neutral-600">
                    for &ldquo;<span className="font-semibold text-neutral-950">{q}</span>&rdquo;
                  </span>
                ) : null}
              </Sub>
              {emptyBody ? <p className="mx-auto mt-3 max-w-md text-base leading-7 text-pretty text-neutral-600">{emptyBody}</p> : null}
              {links.length ? (
                <ul role="list" className="mt-6 flex flex-wrap justify-center gap-2">
                  {links.map((l, i) => (
                    <li key={`${l.label}-${i}`}>
                      <a
                        href={l.href || "#"}
                        className={`inline-flex min-h-11 items-center rounded-full bg-white px-4 text-sm font-semibold text-neutral-800 ring-1 ring-neutral-300 transition ring-inset hover:bg-indigo-50 hover:text-indigo-800 hover:ring-indigo-200 ${focusRing}`}
                      >
                        {l.label}
                      </a>
                    </li>
                  ))}
                </ul>
              ) : null}
            </div>
          )}
        </div>
      </section>
    );
  },
};
```
