# Add the "Alerts Panel" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/alerts-panel) to this Pantheon Content Publisher (P1) Next.js project. Threshold alerts listed by severity with icons, times and action links, or an all-clear state.

## Steps

1. Create `components/puck/alerts-panel-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 { alertsPanelBlock } from "./components/puck/alerts-panel-block";`
3. Register it under `components` as `AlertsPanelBlock: alertsPanelBlock`.
4. Add `"AlertsPanelBlock"` 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/alerts-panel-block.tsx`

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

/**
 * Alerts Panel — threshold alerts in one card: metric, message, severity (info, warning,
 * critical, each with an icon and a written label), time and a link to act on it. Shows
 * "All clear" when the list is empty. Every value is a text field, bindable to a P1 data
 * source. Place inside a Dashboard Grid.
 * Register: `AlertsPanelBlock: alertsPanelBlock` in puck.config.tsx.
 */
// spec: status-colors

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

type Severity = "critical" | "warning" | "info";

type Alert = { metric: string; message: string; severity: Severity; time: string; linkLabel: string; linkHref: string };

export type AlertsPanelProps = {
  title: string;
  headingLevel: Heading;
  subtitle: string;
  alerts: Alert[];
  sort: "severity" | "entered";
  clearMessage: string;
  footnote: string;
};

/** Bound data may say "CRITICAL", "error", "warn"… */
function toSeverity(raw: unknown): Severity {
  const s = String(raw ?? "").toLowerCase();
  if (/crit|error|severe|high|urgent/.test(s)) return "critical";
  if (/warn|medium|caution/.test(s)) return "warning";
  return "info";
}

const RANK: Record<Severity, number> = { critical: 0, warning: 1, info: 2 };

const STYLE: Record<Severity, { label: string; plural: string; icon: string; badge: string; edge: string }> = {
  critical: {
    label: "Critical",
    plural: "critical",
    icon: "text-red-600",
    badge: "bg-red-50 text-red-800 ring-red-600/20",
    edge: "border-red-600",
  },
  warning: {
    label: "Warning",
    plural: "warnings",
    icon: "text-amber-600",
    badge: "bg-amber-50 text-amber-800 ring-amber-600/25",
    edge: "border-amber-500",
  },
  info: {
    label: "Info",
    plural: "info",
    icon: "text-indigo-600",
    badge: "bg-indigo-50 text-indigo-800 ring-indigo-600/20",
    edge: "border-indigo-300",
  },
};

function SeverityIcon({ severity }: { severity: Severity }) {
  if (severity === "critical")
    return (
      <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5">
        <path
          fillRule="evenodd"
          d="M6.701 2.25c.577-.172 1.181-.25 1.799-.25h3c.618 0 1.222.078 1.8.25L17.5 6.2v7.6l-4.2 3.95c-.578.172-1.182.25-1.8.25h-3c-.618 0-1.222-.078-1.8-.25L2.5 13.8V6.2l4.201-3.95ZM10 5.5a.75.75 0 0 1 .75.75v4.5a.75.75 0 0 1-1.5 0v-4.5A.75.75 0 0 1 10 5.5Zm0 9.5a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"
          clipRule="evenodd"
        />
      </svg>
    );
  if (severity === "warning")
    return (
      <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5">
        <path
          fillRule="evenodd"
          d="M8.485 2.495c.673-1.167 2.357-1.167 3.03 0l6.28 10.875c.673 1.167-.17 2.625-1.516 2.625H3.72c-1.347 0-2.189-1.458-1.515-2.625L8.485 2.495ZM10 5a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 10 5Zm0 9a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"
          clipRule="evenodd"
        />
      </svg>
    );
  return (
    <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5">
      <path
        fillRule="evenodd"
        d="M18 10a8 8 0 1 1-16 0 8 8 0 0 1 16 0Zm-7-4a1 1 0 1 1-2 0 1 1 0 0 1 2 0ZM9 9a.75.75 0 0 0 0 1.5h.253a.25.25 0 0 1 .244.304l-.459 2.066A1.75 1.75 0 0 0 10.747 15H11a.75.75 0 0 0 0-1.5h-.253a.25.25 0 0 1-.244-.304l.459-2.066A1.75 1.75 0 0 0 9.253 9H9Z"
        clipRule="evenodd"
      />
    </svg>
  );
}

export const alertsPanelBlock: ComponentConfig<AlertsPanelProps> = {
  label: "Alerts Panel",
  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: "Subtitle", metadata: { help: "e.g. Checked every 15 minutes. Leave blank to hide." } },
    alerts: {
      type: "array",
      label: "Alerts",
      min: 0,
      max: 20,
      getItemSummary: (item) => (item?.metric ? `${STYLE[toSeverity(item.severity)].label} · ${item.metric}` : "Alert"),
      defaultItemProps: { metric: "New alert", message: "", severity: "warning", time: "", linkLabel: "", linkHref: "" },
      arrayFields: {
        metric: { type: "text", label: "Metric", metadata: { help: "What tripped, e.g. Shelter occupancy. Or bind {{ alerts.items }} and {{ item.metric }}." } },
        message: { type: "text", label: "Message", metadata: { help: "The reading and the threshold, e.g. 98% — above the 95% limit." } },
        severity: {
          type: "select",
          label: "Severity",
          options: [
            { label: "Critical", value: "critical" },
            { label: "Warning", value: "warning" },
            { label: "Info", value: "info" },
          ],
          metadata: { help: "Bound values like error, warn or high are understood too." },
        },
        time: { type: "text", label: "Time", metadata: { help: "Shown as written, e.g. 8 min ago or Oct 6, 9:40 AM." } },
        linkLabel: { type: "text", label: "Link label", metadata: { help: "e.g. Open capacity report. Leave blank for no link." } },
        linkHref: { type: "text", label: "Link URL" },
      },
    },
    sort: {
      type: "radio",
      label: "Order",
      options: [
        { label: "Most severe first", value: "severity" },
        { label: "As entered", value: "entered" },
      ],
    },
    clearMessage: { type: "text", label: "All-clear message", metadata: { help: "Shown under \"All clear\" when there are no alerts." } },
    footnote: { type: "text", label: "Footnote", metadata: { help: "Where the alerts come from. Leave blank to hide." } },
  },
  defaultProps: {
    title: "Operations alerts",
    headingLevel: "h3",
    subtitle: "Thresholds checked every 15 minutes",
    alerts: [
      {
        metric: "Emergency shelter beds",
        message: "Occupancy at 98%, above the 95% limit for three nights running.",
        severity: "critical",
        time: "8 min ago",
        linkLabel: "Open capacity report",
        linkHref: "/reports/shelter-capacity",
      },
      {
        metric: "Food pantry inventory",
        message: "Canned protein is down to 11 days of supply. Reorder point is 14 days.",
        severity: "warning",
        time: "1 hr ago",
        linkLabel: "View inventory",
        linkHref: "/reports/pantry-inventory",
      },
      {
        metric: "Volunteer coverage",
        message: "Saturday's mobile market has 4 of 9 shifts filled.",
        severity: "warning",
        time: "3 hr ago",
        linkLabel: "Fill shifts",
        linkHref: "/volunteer/shifts",
      },
      {
        metric: "Donation page",
        message: "Checkout conversion recovered to 3.1% after Tuesday's fix.",
        severity: "info",
        time: "Yesterday",
        linkLabel: "",
        linkHref: "",
      },
    ],
    sort: "severity",
    clearMessage: "Every monitored metric is within its threshold.",
    footnote: "Sample data · Source: operations monitoring rules",
  },
  render: ({ title, headingLevel, subtitle, alerts, sort, clearMessage, footnote }) => {
    const H = headingLevel || "h3";
    const items = (Array.isArray(alerts) ? alerts : [])
      .map((a, i) => ({
        key: `a${i}`,
        order: i,
        metric: a?.metric?.trim() || "",
        message: a?.message?.trim() || "",
        severity: toSeverity(a?.severity),
        time: a?.time?.trim() || "",
        linkLabel: a?.linkLabel?.trim() || "",
        linkHref: a?.linkHref?.trim() || "",
      }))
      .filter((a) => a.metric || a.message);
    if (sort !== "entered") items.sort((a, b) => RANK[a.severity] - RANK[b.severity] || a.order - b.order);
    const counts = (["critical", "warning", "info"] as Severity[])
      .map((s) => ({ s, n: items.filter((a) => a.severity === s).length }))
      .filter((c) => c.n);

    const foot = footnote ? <p className="mt-auto pt-4 text-xs text-neutral-500">{footnote}</p> : null;
    const card =
      "@container 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";

    return (
      <div className={card}>
        <div className="flex flex-wrap items-start justify-between gap-x-4 gap-y-2">
          <div className="min-w-0">
            {title ? <H className="text-sm font-semibold text-neutral-950">{title}</H> : null}
            {subtitle ? <p className="mt-0.5 text-sm text-neutral-500">{subtitle}</p> : null}
          </div>
          {counts.length ? (
            <p className="flex flex-wrap gap-1.5 text-xs font-medium tabular-nums">
              {counts.map((c) => (
                <span key={c.s} className={`inline-flex items-center rounded-md px-1.5 py-0.5 ring-1 ring-inset ${STYLE[c.s].badge}`}>
                  {c.n} {c.n === 1 && c.s === "warning" ? "warning" : STYLE[c.s].plural}
                </span>
              ))}
            </p>
          ) : null}
        </div>

        {items.length ? (
          <ul className="mt-4 divide-y divide-neutral-100 border-y border-neutral-100">
            {items.map((a) => {
              const st = STYLE[a.severity];
              return (
                <li key={a.key} className={`flex gap-3 border-l-2 py-3 pl-3 ${st.edge}`}>
                  <span className={`mt-px shrink-0 ${st.icon}`}>
                    <SeverityIcon severity={a.severity} />
                  </span>
                  <div className="min-w-0 flex-1">
                    <div className="flex flex-wrap items-center gap-x-2 gap-y-1">
                      <span className={`inline-flex items-center rounded-md px-1.5 py-0.5 text-xs font-semibold ring-1 ring-inset ${st.badge}`}>{st.label}</span>
                      {a.metric ? <p className="min-w-0 text-sm font-medium text-pretty text-neutral-950">{a.metric}</p> : null}
                      {a.time ? <span className="text-xs text-neutral-500 tabular-nums @md:ml-auto">{a.time}</span> : null}
                    </div>
                    {a.message ? <p className="mt-1 text-sm text-pretty text-neutral-600 tabular-nums">{a.message}</p> : null}
                    {a.linkLabel && a.linkHref ? (
                      <a
                        href={a.linkHref}
                        className="-my-2 inline-flex min-h-11 items-center gap-1 rounded-md text-sm font-medium text-indigo-700 hover:text-indigo-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                      >
                        {a.linkLabel}
                        <svg aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" className="size-3.5">
                          <path
                            fillRule="evenodd"
                            d="M2 8a.75.75 0 0 1 .75-.75h8.69L8.22 4.03a.75.75 0 0 1 1.06-1.06l4.5 4.5a.75.75 0 0 1 0 1.06l-4.5 4.5a.75.75 0 0 1-1.06-1.06l3.22-3.22H2.75A.75.75 0 0 1 2 8Z"
                            clipRule="evenodd"
                          />
                        </svg>
                        {a.metric ? <span className="sr-only"> for {a.metric}</span> : null}
                      </a>
                    ) : null}
                  </div>
                </li>
              );
            })}
          </ul>
        ) : (
          <div className="mt-4 flex flex-1 flex-col items-center justify-center gap-1.5 rounded-lg border border-dashed border-neutral-200 px-4 py-10 text-center">
            <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-7 text-emerald-600">
              <path
                fillRule="evenodd"
                d="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"
                clipRule="evenodd"
              />
            </svg>
            <p className="text-sm font-semibold text-neutral-900">All clear</p>
            <p className="text-xs text-pretty text-neutral-500">{clearMessage?.trim() || "No alerts right now."}</p>
          </div>
        )}

        {foot}
      </div>
    );
  },
};
```
