"use client"; import * as React from "react"; import { STATEMENT_LOCALES, STATEMENT_MAX_FREE_TEXT, isStatementLocale, type StatementLocale, } from "@accessibit/types"; import { Checkbox } from "../../ui/checkbox"; import { Label } from "../../ui/label"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "../../ui/tabs"; import { Textarea } from "../../ui/textarea"; import { useMessages } from "../../context"; import { fill } from "../../lib/fill"; import { StatementField } from "../StatementField"; import { languagesOmittingSection, type LocalizedTextField, } from "../statementForm"; import type { StatementFormController } from "../formController"; /** The three texts of a language, top to bottom, with the rows each opens on. */ const TEXTS = [ { field: "measuresTaken", id: "measures-taken", rows: 4 }, { field: "knownLimitations", id: "known-limitations", rows: 3 }, { field: "additionalNotes", id: "additional-notes", rows: 3 }, ] as const satisfies readonly { field: LocalizedTextField; id: string; rows: number; }[]; /** * The statement's own words: measures, known limitations and closing notes. * It is published in all three languages, so the free text is written in all * three. One tab per language; a blank tab falls back to English at render * time, and to nothing when English is blank too. * * That last case is easy to miss — a section written in Italian only is left * out of the English and Spanish documents — so under a field written * somewhere but not in English, a note says which versions will go without it * (ACC-527). It is the current state, not a save's verdict, and it never * blocks: an optional section missing from a language is the user's call. * * The closing notice about PDF files sits under the tabs: it is not free * text, it comes from the renderer's own catalog in each language. */ export function TextsSection({ controller, }: { controller: StatementFormController; }) { const messages = useMessages(); const statementDict = messages.statement; const formDict = statementDict.form; const fields = formDict.fields; const { form, patch, patchLocalized, readOnly, locale, onLocaleChange } = controller; const names = (locales: readonly StatementLocale[]) => locales.map((l) => statementDict.languageNames[l]).join(", "); // Per field, not per tab: the gap is the same whichever language is open. const omittedNote = (field: LocalizedTextField) => { const gap = languagesOmittingSection(form, field); return gap ? fill(fields.sectionOmittedIn, { written: names(gap.writtenIn), missing: names(gap.missingIn), }) : undefined; }; return (
{formDict.textsIntro}
{/* One control for the whole page: the tab decides which version is being written AND which one the preview shows, so the form and the document beside it can never disagree about which language is on screen. */}{fields.localizedTextHint}
{STATEMENT_LOCALES.map((tab) => ({fields.pdfDisclaimerHint}