# Add the "Gauge Meter" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/gauge-meter) to this Pantheon Content Publisher (P1) Next.js project. A semicircle gauge with up to three named bands, showing the value and its band as text.

## Steps

1. Create `components/puck/gauge-meter-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 { gaugeMeterBlock } from "./components/puck/gauge-meter-block";`
3. Register it under `components` as `GaugeMeterBlock: gaugeMeterBlock`.
4. Add `"GaugeMeterBlock"` to the best-fitting entry in `categories` (this block's library category is "Dashboards"). Create a category only if none fits.
5. Dashboard widgets are designed to sit inside the Dashboard Grid block (https://p1-blocks.prolificdigital.io/r/dashboard-grid.md). If the project doesn't have it yet, offer to add it too.
6. Run the project's type check (usually `pnpm typecheck`) and resolve anything project-specific.
7. 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-`.
- Data values are text fields on purpose: P1 data-source tokens (`{{ source.field }}`) only bind in text fields. Don't convert them to number fields.
- Don't change prop names in `defaultProps`. Content editors' saved pages depend on them.

## File: `components/puck/gauge-meter-block.tsx`

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

/**
 * Gauge Meter — one value on a semicircle scale split into up to three named bands
 * (e.g. Low / Moderate / High), with the value and its band printed as text inside the arc. Every figure
 * is a text field, so it can be bound to a P1 data source. Place inside a Dashboard Grid.
 * Register: `GaugeMeterBlock: gaugeMeterBlock` in puck.config.tsx.
 */
// spec: status-colors

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

export type GaugeMeterProps = {
  title: string;
  headingLevel: Heading;
  subtitle: string;
  value: string;
  min: string;
  max: string;
  suffix: string;
  thresholds: string;
  lowLabel: string;
  midLabel: string;
  highLabel: string;
  goodWhen: "high" | "low";
  colors: "status" | "brand";
  footnote: string;
};

/** "1,234.5", "$12k" or "-3.2%" → number; anything unparseable → null. */
function toNumber(raw: string | undefined): number | null {
  if (raw == null) return null;
  const cleaned = String(raw).replace(/[^0-9.\-]/g, "");
  if (cleaned === "" || cleaned === "-" || cleaned === ".") return null;
  const n = Number(cleaned);
  return Number.isFinite(n) ? n : null;
}

const fmt = (n: number) => n.toLocaleString("en-US", { maximumFractionDigits: 1 });

const CX = 100;
const CY = 100;
const R = 80;

/** Fraction 0–1 along the arc (left → right over the top) → SVG point. */
function point(f: number, r = R) {
  const a = Math.PI * (1 - f);
  return [CX + r * Math.cos(a), CY - r * Math.sin(a)] as const;
}

function arc(f1: number, f2: number, r = R) {
  const [x1, y1] = point(f1, r);
  const [x2, y2] = point(f2, r);
  return `M${x1.toFixed(2)} ${y1.toFixed(2)} A${r} ${r} 0 0 1 ${x2.toFixed(2)} ${y2.toFixed(2)}`;
}

type Tone = "good" | "warn" | "bad";

const STATUS: Record<Tone, { stroke: string; band: string; badge: string; dot: string }> = {
  good: { stroke: "stroke-emerald-500", band: "stroke-emerald-200", badge: "bg-emerald-50 text-emerald-800 ring-emerald-600/20", dot: "bg-emerald-500" },
  warn: { stroke: "stroke-amber-400", band: "stroke-amber-200", badge: "bg-amber-50 text-amber-800 ring-amber-600/25", dot: "bg-amber-400" },
  bad: { stroke: "stroke-red-500", band: "stroke-red-200", badge: "bg-red-50 text-red-800 ring-red-600/20", dot: "bg-red-500" },
};

const BRAND = [
  { stroke: "stroke-indigo-300", band: "stroke-indigo-100", dot: "bg-indigo-300" },
  { stroke: "stroke-indigo-500", band: "stroke-indigo-200", dot: "bg-indigo-500" },
  { stroke: "stroke-indigo-700", band: "stroke-indigo-300", dot: "bg-indigo-700" },
];

export const gaugeMeterBlock: ComponentConfig<GaugeMeterProps> = {
  label: "Gauge Meter",
  fields: {
    title: { type: "text", label: "Title" },
    headingLevel: {
      type: "select",
      label: "Heading level",
      options: [
        { label: "H2", value: "h2" },
        { label: "H3 (recommended inside a dashboard)", value: "h3" },
        { label: "H4", value: "h4" },
        { label: "Not a heading", value: "p" },
      ],
      metadata: { help: "Sets the page outline for screen readers and search. The look doesn't change." },
    },
    subtitle: { type: "text", label: "Period or subtitle", metadata: { help: "e.g. As of last night's count. Leave blank to hide." } },
    value: { type: "text", label: "Value", metadata: { help: "Type it or bind it, e.g. {{ shelter.occupancy }}." } },
    min: { type: "text", label: "Scale minimum", metadata: { help: "Left end of the gauge. Blank means 0." } },
    max: { type: "text", label: "Scale maximum", metadata: { help: "Right end of the gauge. Blank means 100." } },
    suffix: { type: "text", label: "Unit", metadata: { help: "e.g. % or beds. Leave blank for none." } },
    thresholds: {
      type: "text",
      label: "Band breakpoints",
      metadata: { help: "One or two comma-separated values that split the scale into bands, e.g. 60, 85. Leave blank for one band." },
    },
    lowLabel: { type: "text", label: "Low band label", metadata: { help: "e.g. Capacity available." } },
    midLabel: { type: "text", label: "Middle band label", metadata: { help: "Used only with two breakpoints." } },
    highLabel: { type: "text", label: "High band label", metadata: { help: "e.g. At capacity." } },
    goodWhen: {
      type: "radio",
      label: "Better when the value is",
      options: [
        { label: "High", value: "high" },
        { label: "Low", value: "low" },
      ],
      metadata: { help: "Decides which band is green and which is red when status colors are on." },
    },
    colors: {
      type: "radio",
      label: "Band colors",
      options: [
        { label: "Status (green / amber / red)", value: "status" },
        { label: "Brand", value: "brand" },
      ],
      metadata: { help: "The band name is always shown as text, so meaning never depends on color." },
    },
    footnote: { type: "text", label: "Footnote", metadata: { help: "Where the number comes from. Leave blank to hide." } },
  },
  defaultProps: {
    title: "Emergency shelter occupancy",
    headingLevel: "h3",
    subtitle: "Beds filled, all city shelters",
    value: "78",
    min: "0",
    max: "100",
    suffix: "%",
    thresholds: "60, 85",
    lowLabel: "Beds available",
    midLabel: "Near capacity",
    highLabel: "At capacity",
    goodWhen: "low",
    colors: "status",
    footnote: "Sample data · Source: Coordinated entry nightly count, Oct 6, 2026",
  },
  render: ({ title, headingLevel, subtitle, value, min, max, suffix, thresholds, lowLabel, midLabel, highLabel, goodWhen, colors, footnote }) => {
    const H = headingLevel || "h3";
    const lo = toNumber(min) ?? 0;
    const hiRaw = toNumber(max) ?? 100;
    const hi = hiRaw > lo ? hiRaw : lo + 1;
    const v = toNumber(value);
    const frac = (n: number) => Math.min(1, Math.max(0, (n - lo) / (hi - lo)));
    const sfx = suffix?.trim() ?? "";
    const withUnit = (n: number) => `${fmt(n)}${sfx ? (/^[%°]/.test(sfx) ? sfx : ` ${sfx}`) : ""}`;

    const cuts = (thresholds ?? "")
      .split(",")
      .map((t) => toNumber(t))
      .filter((t): t is number => t !== null && t > lo && t < hi)
      .sort((a, b) => a - b)
      .slice(0, 2);
    const edges = [lo, ...cuts, hi];
    const names =
      cuts.length === 2 ? [lowLabel, midLabel, highLabel] : cuts.length === 1 ? [lowLabel, highLabel] : [""];
    const tones: Tone[] =
      cuts.length === 2 ? ["bad", "warn", "good"] : cuts.length === 1 ? ["bad", "good"] : ["good"];
    if (goodWhen === "low") tones.reverse();
    const brandIdx = cuts.length === 2 ? [0, 1, 2] : cuts.length === 1 ? [0, 2] : [1];
    const bands = edges.slice(0, -1).map((start, i) => {
      const end = edges[i + 1];
      const brand = BRAND[brandIdx[i]];
      const status = STATUS[tones[i]];
      return {
        start,
        end,
        name: names[i]?.trim() || "",
        stroke: colors === "brand" ? brand.stroke : status.stroke,
        band: colors === "brand" ? brand.band : status.band,
        dot: colors === "brand" ? brand.dot : status.dot,
        badge: colors === "brand" ? "bg-indigo-50 text-indigo-800 ring-indigo-600/20" : status.badge,
      };
    });
    const activeIdx = v === null ? -1 : Math.max(0, bands.findIndex((b, i) => v < b.end || i === bands.length - 1));
    const active = activeIdx >= 0 ? bands[activeIdx] : null;
    const showBands = bands.length > 1;
    const f = v === null ? 0 : frac(v);
    const shown = v === null ? "—" : withUnit(v);
    const summary = v === null
      ? `${title || "Gauge"}: no data.`
      : `${title || "Gauge"}: ${shown} on a scale of ${fmt(lo)} to ${fmt(hi)}${active?.name ? `, ${active.name}` : ""}.`;
    const GAP = 0.006;

    return (
      <div className="flex h-full flex-col rounded-xl bg-white p-5 shadow-xs ring-1 ring-neutral-950/5 sm:p-6 not-in-data-[dashboard-grid]:mx-4 not-in-data-[dashboard-grid]:my-8 sm:not-in-data-[dashboard-grid]:mx-auto sm:not-in-data-[dashboard-grid]:max-w-2xl">
        {title || subtitle ? (
          <div>
            {title ? <H className="text-sm font-semibold text-neutral-950">{title}</H> : null}
            {subtitle ? <p className="mt-1 text-sm text-neutral-500">{subtitle}</p> : null}
          </div>
        ) : null}

        <figure className="mx-auto mt-5 w-full max-w-72">
          <div className="relative">
            <svg viewBox="0 0 200 108" preserveAspectRatio="xMidYMid meet" role="img" aria-label={summary} className="block w-full overflow-visible">
              {/* Band ring */}
              {bands.map((b, i) => (
                <path
                  key={`band-${i}`}
                  d={arc(frac(b.start) + (i ? GAP : 0), frac(b.end) - (i < bands.length - 1 ? GAP : 0), R + 12)}
                  fill="none"
                  strokeWidth="4"
                  strokeLinecap="butt"
                  className={showBands ? b.band : "stroke-neutral-200"}
                />
              ))}
              {/* Track and value */}
              <path d={arc(0, 1)} fill="none" strokeWidth="14" strokeLinecap="round" className="stroke-neutral-100" />
              {v !== null && f > 0 ? (
                <path d={arc(0, f)} fill="none" strokeWidth="14" strokeLinecap="round" className={active?.stroke ?? "stroke-indigo-600"} />
              ) : null}
              {/* Breakpoint ticks */}
              {cuts.map((c, i) => {
                const [x1, y1] = point(frac(c), R + 8);
                const [x2, y2] = point(frac(c), R + 17);
                return <line key={`tick-${i}`} x1={x1} y1={y1} x2={x2} y2={y2} strokeWidth="1.5" className="stroke-neutral-400" />;
              })}
            </svg>
            <figcaption className="absolute inset-x-0 bottom-0 flex flex-col items-center px-10 text-center">
              <span className="text-3xl leading-none font-semibold tracking-tight text-neutral-950 tabular-nums sm:text-4xl">{shown}</span>
              {active?.name ? (
                <span className={`mt-2 inline-flex max-w-full items-center gap-1.5 rounded-md px-2 py-0.5 text-xs font-medium ring-1 ring-inset ${active.badge}`}>
                  <span aria-hidden="true" className={`size-1.5 shrink-0 rounded-full ${active.dot}`} />
                  <span className="truncate">{active.name}</span>
                </span>
              ) : v === null ? (
                <span className="mt-2 text-xs text-neutral-500">No data yet</span>
              ) : null}
            </figcaption>
          </div>
          <div aria-hidden="true" className="mt-2 flex justify-between px-1 text-xs text-neutral-500 tabular-nums">
            <span>{withUnit(lo)}</span>
            <span>{withUnit(hi)}</span>
          </div>
        </figure>

        {showBands ? (
          <ul role="list" className="mt-5 flex flex-wrap justify-center gap-x-4 gap-y-1.5 border-t border-neutral-100 pt-4 text-xs text-neutral-600">
            {bands.map((b, i) => (
              <li key={i} className="inline-flex items-center gap-1.5">
                <span aria-hidden="true" className={`size-2 rounded-full ${b.dot}`} />
                <span className={i === activeIdx ? "font-semibold text-neutral-950" : undefined}>{b.name || `Band ${i + 1}`}</span>
                <span className="text-neutral-500 tabular-nums">
                  {fmt(b.start)}–{fmt(b.end)}
                  {sfx && /^[%°]/.test(sfx) ? sfx : ""}
                </span>
                {i === activeIdx ? <span className="sr-only">(current)</span> : null}
              </li>
            ))}
          </ul>
        ) : null}

        {footnote ? <p className="mt-auto pt-4 text-xs text-neutral-500">{footnote}</p> : null}
      </div>
    );
  },
};
```
