"use client"; import * as React from "react"; import type { StatementAuditOption } from "@accessibit/types"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "../ui/select"; import { useSiteAdmin } from "../context"; import { cn } from "../lib/cn"; import { fill } from "../lib/fill"; export type { StatementAuditOption }; /** * Which audit the statement declares (ACC-388). * * The default — and what every statement carried before this existed — is * "the latest", modelled as the sentinel value below rather than as an empty * string, because Radix's Select treats `""` as "no value" and would render * the placeholder instead of the option. * * The option set comes from the client's `auditOptions`, which is * deliberately wider than the domain's audit list: it includes `scheduled` * (Tracker) runs, which are legitimate evidence for a declaration but live on * the Tracker page rather than in the audit log. Offering only what the audit * list shows would make a statement already pinned to a Tracker run unable to * display its own choice. * * Each option names the date, the service that produced it and the number of * pages, because those are exactly the three things that make two audits of * the same site not interchangeable — a one-page extension spot-check and a * 200-page dashboard audit can otherwise look identical in a dropdown while * declaring very different conformance levels. */ export const LATEST_AUDIT = "__latest__"; export function StatementAuditSelect({ value, onChange, options, size = "default", id, className, disabled, }: { /** A job id, or `LATEST_AUDIT`. */ value: string; onChange: (value: string) => void; options: StatementAuditOption[]; size?: "sm" | "default"; id?: string; className?: string; disabled?: boolean; }) { const { messages, format } = useSiteAdmin(); const t = messages.statement.form.auditPicker; const sourceLabels = messages.auditSource; const label = (option: StatementAuditOption) => fill(option.pagesScanned === 1 ? t.optionOne : t.option, { date: option.completedAt ? format.date(option.completedAt) : "—", // `kind` as the fallback: a response from a build that did not send // `source` yet must not render a label with a hole in it. source: sourceLabels[option.source ?? option.kind], pages: String(option.pagesScanned), }); return ( ); }