# Add the "Availability Grid" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/availability-grid) to this Pantheon Content Publisher (P1) Next.js project. A weekly table of fields, courts and rooms showing Open, Booked or Closed each day, with opt-in status colors.

## Steps

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

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

/**
 * Availability Grid — one week of facility availability: fields, courts and shelters down the
 * side, days across the top, and an Open / Booked / Closed status in every cell, always in words.
 * Status colors are opt-in. Ends with a booking link and optional previous/next week links.
 * Register: `AvailabilityGridBlock: availabilityGridBlock` in puck.config.tsx.
 */
// spec: status-colors

type Heading = "h1" | "h2" | "h3" | "h4";
type Kind = "open" | "partial" | "booked" | "closed" | "other";

export type AvailabilityGridProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  weekLabel: string;
  days: string;
  rows: { name: string; detail: string; statuses: string }[];
  statusColors: boolean;
  updatedNote: string;
  bookLabel: string;
  bookHref: string;
  prevWeekHref: string;
  nextWeekHref: string;
};

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

const kindOf = (raw: string): Kind => {
  const v = raw.toLowerCase();
  if (!v) return "other";
  if (/partl|limited|some|few/.test(v)) return "partial";
  if (/^(open|available|free)/.test(v)) return "open";
  if (/book|reserved|full|taken/.test(v)) return "booked";
  if (/clos|maint|unavailable/.test(v)) return "closed";
  return "other";
};

const icons: Record<Kind, string> = {
  open: "M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16Zm3.857-9.809a.75.75 0 0 0-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 1 0-1.06 1.061l2.5 2.5a.75.75 0 0 0 1.137-.089l4-5.5Z",
  partial: "M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16Zm.75-13a.75.75 0 0 0-1.5 0v5c0 .414.336.75.75.75h4a.75.75 0 0 0 0-1.5h-3.25V5Z",
  booked: "M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16ZM8.28 7.22a.75.75 0 0 0-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 1 0 1.06 1.06L10 11.06l1.72 1.72a.75.75 0 1 0 1.06-1.06L11.06 10l1.72-1.72a.75.75 0 0 0-1.06-1.06L10 8.94 8.28 7.22Z",
  closed: "M10 1a4.5 4.5 0 0 0-4.5 4.5V9H5a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-6a2 2 0 0 0-2-2h-.5V5.5A4.5 4.5 0 0 0 10 1Zm3 8V5.5a3 3 0 1 0-6 0V9h6Z",
  other: "M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16ZM6.75 9.25a.75.75 0 0 0 0 1.5h6.5a.75.75 0 0 0 0-1.5h-6.5Z",
};

const neutralStyles: Record<Kind, string> = {
  open: "bg-indigo-50 text-indigo-900 ring-indigo-600/20",
  partial: "bg-white text-indigo-900 ring-indigo-600/40",
  booked: "bg-neutral-200 text-neutral-800 ring-neutral-950/5",
  closed: "bg-neutral-50 text-neutral-600 ring-neutral-300",
  other: "bg-white text-neutral-700 ring-neutral-200",
};

const colorStyles: Record<Kind, string> = {
  open: "bg-emerald-50 text-emerald-800 ring-emerald-600/25",
  partial: "bg-amber-50 text-amber-900 ring-amber-600/30",
  booked: "bg-red-50 text-red-800 ring-red-600/20",
  closed: "bg-neutral-100 text-neutral-700 ring-neutral-300",
  other: "bg-white text-neutral-700 ring-neutral-200",
};

const legend: { kind: Kind; label: string }[] = [
  { kind: "open", label: "Open" },
  { kind: "partial", label: "Partly booked" },
  { kind: "booked", label: "Booked" },
  { kind: "closed", label: "Closed" },
];

export const availabilityGridBlock: ComponentConfig<AvailabilityGridProps> = {
  label: "Availability Grid",
  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." } },
    weekLabel: { type: "text", label: "Week", metadata: { help: "Like Week of October 12, 2026. Also names the table for screen readers." } },
    days: {
      type: "text",
      label: "Day columns",
      metadata: { help: "Separate with commas, like Mon Oct 12, Tue Oct 13. The first word shows larger." },
    },
    rows: {
      type: "array",
      label: "Facilities",
      min: 1,
      max: 30,
      getItemSummary: (item) => item?.name || "Facility",
      defaultItemProps: { name: "New facility", detail: "", statuses: "Open | Open | Open | Open | Open | Open | Open" },
      arrayFields: {
        name: { type: "text", label: "Name" },
        detail: { type: "text", label: "Detail", metadata: { help: "Like the park, surface or lights. Leave blank to hide it." } },
        statuses: {
          type: "textarea",
          label: "Status by day",
          metadata: { help: "One status per day, separated by |, in the same order as the day columns. Use Open, Partly booked, Booked or Closed. Other words show as written." },
        },
      },
    },
    statusColors: {
      type: "radio",
      label: "Status colors",
      options: [
        { label: "On", value: true },
        { label: "Off", value: false },
      ],
      metadata: { help: "Adds green, amber and red. Every status still shows its name and icon, so color is never the only cue." },
    },
    updatedNote: { type: "text", label: "Updated note", metadata: { help: "Like Updated Oct 8 at 9 a.m. Leave blank to hide it." } },
    bookLabel: { type: "text", label: "Booking button text", metadata: { help: "Leave blank to hide the button." } },
    bookHref: { type: "text", label: "Booking link" },
    prevWeekHref: { type: "text", label: "Previous week link", metadata: { help: "Leave blank to hide it." } },
    nextWeekHref: { type: "text", label: "Next week link", metadata: { help: "Leave blank to hide it." } },
  },
  defaultProps: {
    heading: "Field and court availability",
    headingLevel: "h2",
    intro: "See what's open before you book. Times not shown as booked can be reserved online up to 60 days ahead.",
    weekLabel: "Week of October 12, 2026",
    days: "Mon Oct 12, Tue Oct 13, Wed Oct 14, Thu Oct 15, Fri Oct 16, Sat Oct 17, Sun Oct 18",
    rows: [
      { name: "Cedar Run Field 1", detail: "Lighted · natural grass", statuses: "Open | Booked | Open | Partly booked | Booked | Booked | Open" },
      { name: "Cedar Run Field 2", detail: "Lighted · turf", statuses: "Partly booked | Open | Booked | Open | Open | Booked | Booked" },
      { name: "Willow Creek Diamond", detail: "Youth baseball", statuses: "Open | Open | Open | Open | Booked | Booked | Partly booked" },
      { name: "Hillcrest Tennis Courts 1–4", detail: "Lighted until 10 p.m.", statuses: "Open | Open | Partly booked | Open | Open | Partly booked | Open" },
      { name: "Oak Hollow Shelter", detail: "Up to 40 people", statuses: "Closed | Closed | Open | Open | Open | Booked | Booked" },
      { name: "Prairie Room", detail: "Community Center", statuses: "Booked | Open | Open | Booked | Open | Open | Closed" },
    ],
    statusColors: false,
    updatedNote: "Updated Thursday, Oct 8 at 9 a.m. Availability can change. Your booking confirms the time.",
    bookLabel: "Book a field or court",
    bookHref: "/rentals/book",
    prevWeekHref: "/rentals/availability?week=2026-10-05",
    nextWeekHref: "/rentals/availability?week=2026-10-19",
  },
  render: ({ id, heading, headingLevel, intro, weekLabel, days, rows, statusColors, updatedNote, bookLabel, bookHref, prevWeekHref, nextWeekHref }) => {
    const H = headingLevel || "h2";
    const baseId = id || "availability-grid";
    const cols = (days ?? "")
      .split(",")
      .map((d) => d.trim())
      .filter(Boolean);
    const list = (rows ?? []).filter((r) => r?.name);
    const styles = statusColors ? colorStyles : neutralStyles;
    const hasHeader = Boolean(heading || intro);
    const hasNav = Boolean(weekLabel || prevWeekHref || nextWeekHref);
    const captionId = `${baseId}-caption`;
    const navLink = `inline-flex min-h-11 items-center gap-1 rounded-lg px-3 text-sm font-semibold text-neutral-800 ring-1 ring-neutral-300 transition ring-inset hover:bg-neutral-50 ${focusRing}`;
    return (
      <section aria-labelledby={heading ? `${baseId}-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-7xl">
          {hasHeader ? (
            <div className="max-w-2xl">
              {heading ? (
                <H id={`${baseId}-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}

          {hasNav ? (
            <div className={`flex flex-col gap-4 border-b border-neutral-200 pb-5 sm:flex-row sm:items-center sm:justify-between ${hasHeader ? "mt-10 sm:mt-12" : ""}`}>
              {weekLabel ? (
                <p className="flex items-center gap-2.5 text-lg font-semibold text-neutral-950">
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5 shrink-0 text-indigo-700">
                    <path fillRule="evenodd" d="M5.75 2a.75.75 0 0 1 .75.75V4h7V2.75a.75.75 0 0 1 1.5 0V4h.25A2.75 2.75 0 0 1 18 6.75v8.5A2.75 2.75 0 0 1 15.25 18H4.75A2.75 2.75 0 0 1 2 15.25v-8.5A2.75 2.75 0 0 1 4.75 4H5V2.75A.75.75 0 0 1 5.75 2Zm-1 5.5c-.69 0-1.25.56-1.25 1.25v6.5c0 .69.56 1.25 1.25 1.25h10.5c.69 0 1.25-.56 1.25-1.25v-6.5c0-.69-.56-1.25-1.25-1.25H4.75Z" clipRule="evenodd" />
                  </svg>
                  {weekLabel}
                </p>
              ) : (
                <span />
              )}
              {prevWeekHref || nextWeekHref ? (
                <nav aria-label="Change week" className="flex gap-2">
                  {prevWeekHref ? (
                    <a href={prevWeekHref} className={navLink}>
                      <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>
                      Previous week
                    </a>
                  ) : null}
                  {nextWeekHref ? (
                    <a href={nextWeekHref} className={navLink}>
                      Next week
                      <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>
                    </a>
                  ) : null}
                </nav>
              ) : null}
            </div>
          ) : null}

          {cols.length && list.length ? (
            <div
              role="region"
              aria-labelledby={captionId}
              tabIndex={0}
              className={`relative -mx-4 overflow-x-auto sm:mx-0 ${focusRing} focus-visible:-outline-offset-2 ${hasNav ? "mt-6" : hasHeader ? "mt-10 sm:mt-12" : ""}`}
            >
              <table className="w-full border-separate border-spacing-0 text-left text-sm">
                <caption id={captionId} className="sr-only">
                  {[heading || "Facility availability", weekLabel].filter(Boolean).join(", ")}
                </caption>
                <thead>
                  <tr>
                    <th scope="col" className="sticky left-0 z-10 min-w-40 border-b border-neutral-300 bg-white px-4 py-3 align-bottom text-xs font-semibold tracking-wide text-neutral-700 uppercase sm:min-w-52 sm:pl-0">
                      Facility
                    </th>
                    {cols.map((day, c) => {
                      const [first, ...rest] = day.split(/\s+/);
                      return (
                        <th key={`${day}-${c}`} scope="col" className="min-w-28 border-b border-neutral-300 px-2 py-3 text-center align-bottom font-normal">
                          <span className="block text-sm font-semibold text-neutral-950">{first}</span>
                          {rest.length ? <span className="block text-xs text-neutral-600 tabular-nums">{rest.join(" ")}</span> : null}
                        </th>
                      );
                    })}
                  </tr>
                </thead>
                <tbody>
                  {list.map((row, r) => {
                    const cells = (row.statuses ?? "").split("|").map((s) => s.trim());
                    return (
                      <tr key={`${row.name}-${r}`}>
                        <th scope="row" className="sticky left-0 z-10 border-b border-neutral-200 bg-white px-4 py-3 align-middle font-normal sm:pl-0">
                          <span className="block font-semibold text-neutral-950">{row.name}</span>
                          {row.detail ? <span className="mt-0.5 block text-xs leading-5 text-neutral-600">{row.detail}</span> : null}
                        </th>
                        {cols.map((day, c) => {
                          const text = cells[c] || "";
                          const kind = kindOf(text);
                          return (
                            <td key={`${day}-${c}`} className="border-b border-neutral-200 px-1.5 py-2 text-center align-middle">
                              {text ? (
                                <span className={`inline-flex min-h-9 w-full items-center justify-center gap-1 rounded-md px-2 py-1 text-xs leading-4 font-semibold ring-1 ring-inset ${styles[kind]}`}>
                                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-3.5 shrink-0">
                                    <path fillRule="evenodd" d={icons[kind]} clipRule="evenodd" />
                                  </svg>
                                  {text}
                                </span>
                              ) : (
                                <span className="text-neutral-500">
                                  <span aria-hidden="true">–</span>
                                  <span className="sr-only">No information</span>
                                </span>
                              )}
                            </td>
                          );
                        })}
                      </tr>
                    );
                  })}
                </tbody>
              </table>
            </div>
          ) : null}

          <div className="mt-6 flex flex-col gap-5 lg:flex-row lg:items-start lg:justify-between lg:gap-10">
            <div className="min-w-0">
              {cols.length && list.length ? (
                <ul role="list" aria-label="Status key" className="flex flex-wrap gap-2">
                  {legend.map((l) => (
                    <li key={l.kind} className={`inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-semibold ring-1 ring-inset ${styles[l.kind]}`}>
                      <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-3.5 shrink-0">
                        <path fillRule="evenodd" d={icons[l.kind]} clipRule="evenodd" />
                      </svg>
                      {l.label}
                    </li>
                  ))}
                </ul>
              ) : null}
              {updatedNote ? <p className="mt-3 max-w-2xl text-sm leading-6 text-pretty text-neutral-600">{updatedNote}</p> : null}
            </div>
            {bookLabel ? (
              <a
                href={bookHref || "#"}
                className={`inline-flex min-h-11 shrink-0 items-center justify-center gap-2 self-start rounded-lg bg-indigo-700 px-5 py-2.5 text-sm font-semibold text-white shadow-sm transition hover:bg-indigo-600 ${focusRing}`}
              >
                {bookLabel}
                <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 shrink-0">
                  <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>
        </div>
      </section>
    );
  },
};
```
