"use client"; import * as React from "react"; import { CheckIcon, SquarePenIcon } from "lucide-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "../ui/accordion"; import { Badge } from "../ui/badge"; import { Card } from "../ui/card"; import { Skeleton } from "../ui/skeleton"; import { useMessages } from "../context"; import { STATEMENT_TOUR_ANCHORS, TOUR_VARIANT } from "../tour"; import { fill } from "../lib/fill"; import type { StatementFormController } from "./formController"; import { STATEMENT_SECTIONS, type SectionStatus, type StatementSection, } from "./statementSections"; import { ContactSection } from "./sections/ContactSection"; import { ConformanceSection, type StatementAuditChoice, } from "./sections/ConformanceSection"; import { NonAccessibleSection } from "./sections/NonAccessibleSection"; import { OrganizationSection } from "./sections/OrganizationSection"; import { SiteSection } from "./sections/SiteSection"; import { TextsSection } from "./sections/TextsSection"; /** * The statement's data, in six sections that open and close by themselves * (ACC-540). Each carries its mark, done or still to do, and several can be * open at once: the page opens the ones with something missing, and a save * that cannot generate opens the section of the first gap before it moves the * focus there. * * A closed section keeps its fields out of the page, so which sections are * open is the page's state, not the card's. * * While the statement is being read (`loading`) the card holds its place and * shows neither the count nor the sections: both would be of a form that is * about to be replaced, and so would anything typed into it. */ export function StatementFormCard({ controller, audit, statuses, open, onOpenChange, canGenerate, loading = false, }: { controller: StatementFormController; audit: StatementAuditChoice; statuses: Record; open: StatementSection[]; onOpenChange: (open: StatementSection[]) => void; /** Nothing required is missing: the count is good news, not a warning. */ canGenerate: boolean; /** The statement has not been read yet. */ loading?: boolean; }) { const messages = useMessages(); const formDict = messages.statement.form; const done = STATEMENT_SECTIONS.filter( (section) => statuses[section] === "done", ).length; const sections: Record< StatementSection, { title: string; body: React.ReactNode } > = { organization: { title: formDict.sections.organization, body: , }, contact: { title: formDict.sections.people, body: , }, site: { title: formDict.sections.site, body: , }, conformance: { title: formDict.sections.conformance, body: , }, nonAccessible: { title: formDict.sections.nonAccessible, body: , }, texts: { title: formDict.sections.texts, body: , }, }; return (

{formDict.dataTitle}

{formDict.requiredNote}

{loading ? ( ) : ( {fill(formDict.sectionsComplete, { done: String(done), total: String(STATEMENT_SECTIONS.length), })} )}
{loading ? ( // One row per section, as tall as a closed one (a 56px trigger and // its rule), so the card is the size it will be.
{STATEMENT_SECTIONS.map((section) => (
))}
) : ( onOpenChange(value as StatementSection[]) } className="mx-6 border-t" > {STATEMENT_SECTIONS.map((section) => ( {sections[section].title} {sections[section].body} ))} )}
); }