# Add the "League Standings" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/league-standings) to this Pantheon Content Publisher (P1) Next.js project. Division standings tables that compute winning percentage and games behind, sort teams, and add rain-out info.

## Steps

1. Create `components/puck/league-standings-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 { leagueStandingsBlock } from "./components/puck/league-standings-block";`
3. Register it under `components` as `LeagueStandingsBlock: leagueStandingsBlock`.
4. Add `"LeagueStandingsBlock"` 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/league-standings-block.tsx`

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

/**
 * League Standings — one table per division with wins, losses and ties. Winning percentage and
 * games behind are computed and teams are sorted by them, so editors only type results.
 * Register: `LeagueStandingsBlock: leagueStandingsBlock` in puck.config.tsx.
 */

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

type Team = { team: string; wins: string; losses: string; ties: string; streak: string };

export type LeagueStandingsProps = {
  league: string;
  season: string;
  heading: string;
  headingLevel: Heading;
  intro: string;
  asOf: string;
  divisions: {
    division: string;
    teams: Team[];
  }[];
  scheduleLabel: string;
  scheduleHref: string;
  rainoutTitle: string;
  rainoutText: string;
  rainoutPhone: string;
};

const childHeading = { 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-700";

const num = (v: unknown) => {
  const n = typeof v === "number" ? v : Number(String(v ?? "").replace(/[^\d.-]/g, ""));
  return Number.isFinite(n) && n > 0 ? Math.floor(n) : 0;
};

// Baseball-style: ".667", "1.000". A tie counts as half a win.
const formatPct = (pct: number | null) => {
  if (pct === null) return "—";
  if (pct >= 1) return "1.000";
  return pct.toFixed(3).replace(/^0/, "");
};

const formatGb = (gb: number) => (gb <= 0 ? "—" : Number.isInteger(gb) ? String(gb) : gb < 1 ? "½" : `${Math.floor(gb)}½`);

const streakWords: Record<string, string> = { W: "Won", L: "Lost", T: "Tied" };

const spokenStreak = (s: string) => {
  const m = /^\s*([WLT])\s*(\d+)\s*$/i.exec(s || "");
  if (!m) return s;
  return `${streakWords[m[1].toUpperCase()]} ${Number(m[2])} in a row`;
};

const columns = [
  { key: "w", short: "W", long: "Wins" },
  { key: "l", short: "L", long: "Losses" },
  { key: "t", short: "T", long: "Ties" },
  { key: "pct", short: "PCT", long: "Winning percentage" },
  { key: "gb", short: "GB", long: "Games behind the leader" },
  { key: "strk", short: "STRK", long: "Current streak" },
] as const;

const slugify = (s: string) =>
  s
    .toLowerCase()
    .replace(/[^a-z0-9]+/g, "-")
    .replace(/^-|-$/g, "");

export const leagueStandingsBlock: ComponentConfig<LeagueStandingsProps> = {
  label: "League Standings",
  fields: {
    league: { type: "text", label: "League", metadata: { help: "Shown small above the heading, like \"Youth Coach-Pitch Baseball\"." } },
    season: { type: "text", label: "Season", metadata: { help: "Like Fall 2026. Shown next to the league name." } },
    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." } },
    asOf: { type: "text", label: "Standings as of", metadata: { help: "Like \"Through games of Oct 7\". Change it whenever you enter results." } },
    divisions: {
      type: "array",
      label: "Divisions",
      min: 1,
      max: 12,
      getItemSummary: (item) => item?.division || "Division",
      defaultItemProps: {
        division: "New division",
        teams: [
          { team: "Team 1", wins: "0", losses: "0", ties: "0", streak: "" },
          { team: "Team 2", wins: "0", losses: "0", ties: "0", streak: "" },
        ],
      },
      arrayFields: {
        division: { type: "text", label: "Division name", metadata: { help: "Like \"8U Coach Pitch, East\". Each division gets its own table." } },
        teams: {
          type: "array",
          label: "Teams",
          min: 1,
          max: 24,
          getItemSummary: (item) => (item?.team ? `${item.team} (${num(item.wins)}-${num(item.losses)}${num(item.ties) ? `-${num(item.ties)}` : ""})` : "Team"),
          defaultItemProps: { team: "New team", wins: "0", losses: "0", ties: "0", streak: "" },
          arrayFields: {
            team: { type: "text", label: "Team" },
            wins: { type: "text", label: "Wins", metadata: { help: "Type it or bind it to a data source, e.g. {{ item.wins }}." } },
            losses: { type: "text", label: "Losses" },
            ties: { type: "text", label: "Ties" },
            streak: { type: "text", label: "Streak", metadata: { help: "W, L or T plus a number, like W3. Leave blank if no games yet." } },
          },
        },
      },
    },
    scheduleLabel: { type: "text", label: "Schedule link text", metadata: { help: "Leave blank to hide the link." } },
    scheduleHref: { type: "text", label: "Schedule link" },
    rainoutTitle: { type: "text", label: "Rain-out title", metadata: { help: "Leave the title and details blank to hide the box." } },
    rainoutText: { type: "textarea", label: "Rain-out details" },
    rainoutPhone: { type: "text", label: "Rain-out phone", metadata: { help: "Written the way people dial it, like 555-0142. Leave blank to hide it." } },
  },
  defaultProps: {
    league: "Youth Coach-Pitch Baseball",
    season: "Fall 2026",
    heading: "Standings",
    headingLevel: "h2",
    intro: "Teams are ranked by winning percentage. The top two in each division play in the end-of-season jamboree on Nov 1.",
    asOf: "Through games of Wednesday, Oct 7",
    divisions: [
      {
        division: "8U East",
        teams: [
          { team: "Cedar Valley Cardinals", wins: "8", losses: "2", ties: "0", streak: "W4" },
          { team: "Lakeside Lightning", wins: "7", losses: "2", ties: "1", streak: "W1" },
          { team: "Miller Park Muskrats", wins: "5", losses: "5", ties: "0", streak: "L2" },
          { team: "Oakmont Owls", wins: "3", losses: "6", ties: "1", streak: "T1" },
          { team: "Northside Nighthawks", wins: "1", losses: "9", ties: "0", streak: "L5" },
        ],
      },
      {
        division: "8U West",
        teams: [
          { team: "Willow Bend Wildcats", wins: "6", losses: "3", ties: "1", streak: "W2" },
          { team: "Riverfront River Otters", wins: "7", losses: "3", ties: "0", streak: "L1" },
          { team: "Knob Hill Hornets", wins: "4", losses: "6", ties: "0", streak: "W1" },
          { team: "Prairie Hawks", wins: "2", losses: "7", ties: "1", streak: "L3" },
        ],
      },
    ],
    scheduleLabel: "Full schedule and results",
    scheduleHref: "/leagues/coach-pitch/schedule",
    rainoutTitle: "Rain-outs",
    rainoutText: "Check field conditions by 3 p.m. on game days. Rained-out games are rescheduled by the league office within a week, and your coach will share the new date.",
    rainoutPhone: "555-0142",
  },
  render: ({ id, league, season, heading, headingLevel, intro, asOf, divisions, scheduleLabel, scheduleHref, rainoutTitle, rainoutText, rainoutPhone }) => {
    const H = headingLevel || "h2";
    const Sub = childHeading[headingLevel] || "h3";
    const baseId = id || "league-standings";
    const eyebrow = [league, season].filter(Boolean).join(" · ");
    const tables = (divisions ?? [])
      .filter((d) => d?.division || d?.teams?.length)
      .map((d, i) => {
        const rows = (d.teams ?? [])
          .filter((t) => t?.team)
          .map((t) => {
            const w = num(t.wins);
            const l = num(t.losses);
            const tie = num(t.ties);
            const gp = w + l + tie;
            return { team: t.team, w, l, t: tie, streak: (t.streak || "").trim().toUpperCase(), pct: gp ? (w + tie / 2) / gp : null };
          })
          .sort((a, b) => (b.pct ?? -1) - (a.pct ?? -1) || b.w - a.w || a.l - b.l || a.team.localeCompare(b.team));
        const leader = rows[0];
        const withGb = rows.map((r) => ({ ...r, gb: leader && r.pct !== null ? (leader.w - r.w + (r.l - leader.l)) / 2 : 0 }));
        return { name: d.division || `Division ${i + 1}`, anchor: `${baseId}-${slugify(d.division || String(i + 1)) || i + 1}`, rows: withGb };
      });
    const hasRainout = Boolean(rainoutTitle || rainoutText);
    const tel = (rainoutPhone || "").replace(/[^\d+]/g, "");

    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-5xl">
          <div className="flex flex-col gap-6 md:flex-row md:items-end md:justify-between">
            <div className="max-w-2xl">
              {eyebrow ? <p className="text-sm font-semibold tracking-wide text-indigo-700">{eyebrow}</p> : null}
              {heading ? (
                <H id={`${baseId}-heading`} className="mt-2 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>
            {scheduleLabel ? (
              <a
                href={scheduleHref || "#"}
                className={`group inline-flex min-h-11 shrink-0 items-center gap-2 self-start rounded-lg bg-neutral-950 px-4 py-2.5 text-sm font-semibold text-white transition hover:bg-indigo-700 md:self-auto ${focusRing}`}
              >
                <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 shrink-0">
                  <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>
                {scheduleLabel}
              </a>
            ) : null}
          </div>

          {tables.length > 1 ? (
            <nav aria-label="Divisions" className="mt-8 flex flex-wrap items-center gap-2">
              <span className="mr-1 text-sm text-neutral-600">Jump to</span>
              {tables.map((t) => (
                <a
                  key={t.anchor}
                  href={`#${t.anchor}`}
                  className={`inline-flex min-h-11 items-center rounded-full bg-neutral-100 px-4 text-sm font-medium text-neutral-800 ring-1 ring-neutral-200 ring-inset hover:bg-indigo-50 hover:text-indigo-900 hover:ring-indigo-600/20 ${focusRing}`}
                >
                  {t.name}
                </a>
              ))}
            </nav>
          ) : null}

          {tables.map((t) => {
            const captionId = `${t.anchor}-caption`;
            return (
              <div key={t.anchor} id={t.anchor} className="mt-12 scroll-mt-8">
                <div className="flex flex-wrap items-baseline justify-between gap-x-6 gap-y-1 border-b border-neutral-950 pb-3">
                  <Sub className="text-xl font-semibold tracking-tight text-neutral-950">{t.name}</Sub>
                  {asOf ? <p className="text-sm text-neutral-600">{asOf}</p> : null}
                </div>
                {t.rows.length ? (
                  <div
                    role="region"
                    aria-labelledby={captionId}
                    tabIndex={0}
                    className={`relative -mx-4 overflow-x-auto px-4 sm:mx-0 sm:px-0 ${focusRing}`}
                  >
                    <table className="w-full min-w-lg border-collapse text-left">
                      <caption id={captionId} className="sr-only">
                        {[league, season, t.name].filter(Boolean).join(", ")} standings{asOf ? `, ${asOf.charAt(0).toLowerCase()}${asOf.slice(1)}` : ""}
                      </caption>
                      <thead>
                        <tr className="border-b border-neutral-200">
                          <th scope="col" className="w-10 py-3 pr-2 text-xs font-semibold text-neutral-600">
                            <span aria-hidden="true">#</span>
                            <span className="sr-only">Rank</span>
                          </th>
                          <th scope="col" className="py-3 pr-4 text-xs font-semibold tracking-wide text-neutral-600 uppercase">
                            Team
                          </th>
                          {columns.map((c) => (
                            <th key={c.key} scope="col" className="w-14 py-3 pl-3 text-right text-xs font-semibold tracking-wide text-neutral-600 uppercase">
                              <abbr title={c.long} className="no-underline">
                                <span aria-hidden="true">{c.short}</span>
                                <span className="sr-only">{c.long}</span>
                              </abbr>
                            </th>
                          ))}
                        </tr>
                      </thead>
                      <tbody className="divide-y divide-neutral-200">
                        {t.rows.map((r, i) => {
                          const first = i === 0 && r.pct !== null;
                          return (
                            <tr key={`${r.team}-${i}`} className={first ? "bg-indigo-50/60" : undefined}>
                              <td className="py-3.5 pr-2 text-sm text-neutral-600 tabular-nums">{i + 1}</td>
                              <th scope="row" className="py-3.5 pr-4 text-sm font-semibold text-neutral-950">
                                <span className="flex items-center gap-2">
                                  {r.team}
                                  {first ? (
                                    <span className="inline-flex items-center gap-1 rounded-full bg-white px-2 py-0.5 text-xs font-semibold whitespace-nowrap text-indigo-800 ring-1 ring-indigo-600/20 ring-inset">
                                      <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-3 shrink-0">
                                        <path fillRule="evenodd" d="M10.868 2.884c-.321-.772-1.415-.772-1.736 0l-1.83 4.401-4.753.381c-.833.067-1.171 1.107-.536 1.651l3.62 3.102-1.106 4.637c-.194.813.691 1.456 1.405 1.02L10 15.591l4.069 2.485c.713.436 1.598-.207 1.404-1.02l-1.106-4.637 3.62-3.102c.635-.544.297-1.584-.536-1.65l-4.752-.382-1.831-4.401Z" clipRule="evenodd" />
                                      </svg>
                                      Leader
                                    </span>
                                  ) : null}
                                </span>
                              </th>
                              <td className="py-3.5 pl-3 text-right text-sm text-neutral-950 tabular-nums">{r.w}</td>
                              <td className="py-3.5 pl-3 text-right text-sm text-neutral-950 tabular-nums">{r.l}</td>
                              <td className="py-3.5 pl-3 text-right text-sm text-neutral-950 tabular-nums">{r.t}</td>
                              <td className="py-3.5 pl-3 text-right text-sm font-semibold text-neutral-950 tabular-nums">{formatPct(r.pct)}</td>
                              <td className="py-3.5 pl-3 text-right text-sm text-neutral-700 tabular-nums">
                                {r.gb <= 0 ? (
                                  <>
                                    <span aria-hidden="true">—</span>
                                    <span className="sr-only">{r.pct === null ? "No games yet" : first ? "Leader" : "Tied for first"}</span>
                                  </>
                                ) : (
                                  formatGb(r.gb)
                                )}
                              </td>
                              <td className="py-3.5 pl-3 text-right text-sm whitespace-nowrap text-neutral-700 tabular-nums">
                                {r.streak ? (
                                  <>
                                    <span aria-hidden="true">{r.streak}</span>
                                    <span className="sr-only">{spokenStreak(r.streak)}</span>
                                  </>
                                ) : (
                                  <>
                                    <span aria-hidden="true">—</span>
                                    <span className="sr-only">No streak</span>
                                  </>
                                )}
                              </td>
                            </tr>
                          );
                        })}
                      </tbody>
                    </table>
                  </div>
                ) : (
                  <p className="py-6 text-sm text-neutral-600">No teams entered for this division yet.</p>
                )}
              </div>
            );
          })}

          {tables.some((t) => t.rows.length) ? (
            <dl className="mt-6 flex flex-wrap gap-x-5 gap-y-1 text-xs leading-5 text-neutral-600">
              {columns.map((c) => (
                <div key={c.key} className="flex gap-1">
                  <dt className="font-semibold text-neutral-800">{c.short}</dt>
                  <dd>{c.long.toLowerCase()}</dd>
                </div>
              ))}
              <div className="flex basis-full gap-1">
                <dt className="sr-only">Note</dt>
                <dd>Winning percentage counts a tie as half a win. Ranks update when results are entered.</dd>
              </div>
            </dl>
          ) : null}

          {hasRainout ? (
            <aside aria-label={rainoutTitle || "Rain-outs"} className="mt-12 flex flex-col gap-4 rounded-2xl bg-neutral-50 p-6 ring-1 ring-neutral-200 ring-inset sm:flex-row sm:items-start sm:gap-5 sm:p-8">
              <span className="flex size-11 shrink-0 items-center justify-center rounded-xl bg-white text-indigo-700 ring-1 ring-neutral-200">
                <svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.6} strokeLinecap="round" strokeLinejoin="round" className="size-6">
                  <path d="M7 15a4 4 0 0 1-.7-7.94A5.5 5.5 0 0 1 17 7.5a3.75 3.75 0 0 1 .5 7.47M8 18l-1 2m5-2-1 2m5-2-1 2" />
                </svg>
              </span>
              <div className="min-w-0">
                {rainoutTitle ? <p className="text-base font-semibold text-neutral-950">{rainoutTitle}</p> : null}
                {rainoutText ? <p className="mt-1 max-w-2xl text-sm leading-6 text-pretty text-neutral-700">{rainoutText}</p> : null}
                {rainoutPhone ? (
                  <p className="mt-2 text-sm text-neutral-700">
                    Rain-out line:{" "}
                    <a
                      href={tel ? `tel:${tel}` : undefined}
                      className={`inline-flex min-h-11 items-center rounded font-semibold text-indigo-700 tabular-nums underline decoration-indigo-300 underline-offset-4 hover:decoration-indigo-700 ${focusRing}`}
                    >
                      {rainoutPhone}
                    </a>
                  </p>
                ) : null}
              </div>
            </aside>
          ) : null}
        </div>
      </section>
    );
  },
};
```
