{
  "version": 3,
  "sources": ["../../../../src/components/dataform-layouts/details/index.tsx"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tNormalizedForm,\n\tNormalizedDetailsLayout,\n\tFieldLayoutProps,\n} from '../../../types';\nimport DataFormContext from '../../dataform-context';\nimport { DataFormLayout } from '../data-form-layout';\nimport { DEFAULT_LAYOUT } from '../normalize-form';\nimport useReportValidity from '../../../hooks/use-report-validity';\nimport ValidationBadge from '../validation-badge';\n\nexport default function FormDetailsField< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\tvalidity,\n}: FieldLayoutProps< Item > ) {\n\tconst { fields } = useContext( DataFormContext );\n\tconst detailsRef = useRef< HTMLDetailsElement >( null );\n\tconst contentRef = useRef< HTMLDivElement >( null );\n\tconst [ touched, setTouched ] = useState( false );\n\tconst [ isOpen, setIsOpen ] = useState( false );\n\n\tconst form: NormalizedForm = useMemo(\n\t\t() => ( {\n\t\t\tlayout: DEFAULT_LAYOUT,\n\t\t\tfields: field.children ?? [],\n\t\t} ),\n\t\t[ field ]\n\t);\n\n\t// Track the open/close state of the native details element.\n\tuseEffect( () => {\n\t\tconst details = detailsRef.current;\n\t\tif ( ! details ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst handleToggle = () => {\n\t\t\tconst nowOpen = details.open;\n\t\t\t// Mark as touched when collapsing (going from open to closed).\n\t\t\tif ( ! nowOpen ) {\n\t\t\t\tsetTouched( true );\n\t\t\t}\n\t\t\tsetIsOpen( nowOpen );\n\t\t};\n\n\t\tdetails.addEventListener( 'toggle', handleToggle );\n\t\treturn () => {\n\t\t\tdetails.removeEventListener( 'toggle', handleToggle );\n\t\t};\n\t}, [] );\n\n\t// When expanded after being touched, trigger reportValidity to show\n\t// field-level errors.\n\tuseReportValidity( contentRef, isOpen && touched );\n\n\t// Mark as touched when any field inside is blurred.\n\tconst handleBlur = useCallback( () => {\n\t\tsetTouched( true );\n\t}, [] );\n\n\tif ( ! field.children ) {\n\t\treturn null;\n\t}\n\n\t// Find the summary field definition if specified\n\tconst summaryFieldId =\n\t\t( field.layout as NormalizedDetailsLayout ).summary ?? '';\n\tconst summaryField = summaryFieldId\n\t\t? fields.find( ( fieldDef ) => fieldDef.id === summaryFieldId )\n\t\t: undefined;\n\n\t// Render the summary content\n\tlet summaryContent;\n\tif ( summaryField && summaryField.render ) {\n\t\t// Use the field's render function to display the current value\n\t\tsummaryContent = (\n\t\t\t<summaryField.render item={ data } field={ summaryField } />\n\t\t);\n\t} else {\n\t\t// Fall back to the label\n\t\tsummaryContent = field.label || __( 'More details' );\n\t}\n\n\treturn (\n\t\t<details\n\t\t\tref={ detailsRef }\n\t\t\tclassName=\"dataforms-layouts-details__details\"\n\t\t>\n\t\t\t<summary className=\"dataforms-layouts-details__summary\">\n\t\t\t\t<Stack\n\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\talign=\"center\"\n\t\t\t\t\tgap=\"md\"\n\t\t\t\t\tclassName=\"dataforms-layouts-details__summary-content\"\n\t\t\t\t>\n\t\t\t\t\t{ summaryContent }\n\t\t\t\t\t{ touched && <ValidationBadge validity={ validity } /> }\n\t\t\t\t</Stack>\n\t\t\t</summary>\n\t\t\t<div\n\t\t\t\tref={ contentRef }\n\t\t\t\tclassName=\"dataforms-layouts-details__content\"\n\t\t\t\tonBlur={ handleBlur }\n\t\t\t>\n\t\t\t\t<DataFormLayout\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tvalidity={ validity?.children }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</details>\n\t);\n}\n"],
  "mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA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