import { ReactNode, useEffect, useRef, useId } from 'react'; import clsx from 'clsx'; import { useLocalization } from '@akinon/next/hooks'; import { partAttrs } from '@akinon/pz-theme/src/utils/part-styles'; import { Icon } from '@theme/components'; export type SectionStatus = 'locked' | 'active' | 'completed'; interface AccordionSectionProps { step: number; title: string; status: SectionStatus; summary?: ReactNode; onEdit?: () => void; editable?: boolean; children: ReactNode; dataTestId?: string; padded?: boolean; } export const AccordionSection = ({ step, title, status, summary, onEdit, editable = true, children, dataTestId, padded = true }: AccordionSectionProps) => { const { t } = useLocalization(); const isOpen = status === 'active'; const isCompleted = status === 'completed'; const isLocked = status === 'locked'; const contentRef = useRef(null); const headerId = useId(); const panelId = useId(); const wasOpenRef = useRef(isOpen); useEffect(() => { if (isOpen && !wasOpenRef.current && contentRef.current) { const firstFocusable = contentRef.current.querySelector( 'input:not([disabled]), button:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])' ); firstFocusable?.focus({ preventScroll: true }); } wasOpenRef.current = isOpen; }, [isOpen]); return (

{title}

{isCompleted && editable && onEdit && ( )}
{isCompleted && summary && (
{summary}
)}
); }; export default AccordionSection;