"use client"; import * as React from "react"; import { STATEMENT_MAX_FREE_TEXT } from "@accessibit/types"; import { Textarea } from "../../ui/textarea"; import { useMessages } from "../../context"; import { fill } from "../../lib/fill"; import { StatementField, StatementYesNo } from "../StatementField"; import { ANSWER_REASONS, languagesMissingReason } from "../statementForm"; import type { StatementFormController } from "../formController"; /** The id of each question's row, beside the id of its text in * `ANSWER_REASONS`. */ const ANSWER_IDS = { lawNonCompliance: "law-non-compliance", disproportionateBurden: "disproportionate-burden", outOfScopeContent: "out-of-scope-content", } as const satisfies Record<(typeof ANSWER_REASONS)[number]["answer"], string>; /** * Mirrors the document's "Contenuti non accessibili" list: three questions, * and under each "Yes" what it covers. * * A "Yes" says what it covers per language, like the rest of the free text: * the textarea edits the language the page is set to, and a blank one falls * back to English when the document is rendered. It opens right under its * own question, so which answer a text belongs to is never in doubt. */ export function NonAccessibleSection({ controller, }: { controller: StatementFormController; }) { const messages = useMessages(); const statementDict = messages.statement; const formDict = statementDict.form; const fields = formDict.fields; const { form, patch, patchLocalized, showErrors, missing, readOnly, locale } = controller; return (
{ANSWER_REASONS.map(({ answer, reason, id, placeholder }) => { // Flagged only on a language that is itself blank: a filled Italian // box is not the gap, the English one is. const missingIn = languagesMissingReason(form, reason); const invalid = showErrors && missing.has(reason) && missingIn.includes(locale); return ( patch(answer, v)} yesLabel={fields.answerYes} noLabel={fields.answerNo} disabled={readOnly} /> {form[answer] && ( statementDict.languageNames[l]) .join(", "), }) : undefined } >