import { __ } from '@wordpress/i18n';
import { useBlockProps, InnerBlocks, useInnerBlocksProps, InspectorControls } from '@wordpress/block-editor';
import { PanelBody, ToggleControl, __experimentalUnitControl as UnitControl } from '@wordpress/components';
import './editor.scss';

export default function Edit(props) {
    const { attributes, setAttributes } = props;
    const { maxWidth = '100%', expandVertical = true } = attributes; // Default value for maxWidth if not set

    // Function to handle the change of maxWidth
    const handleMaxWidthChange = (value) => {
        setAttributes({ maxWidth: value });
    };

    const blockProps = useBlockProps();  // Standard block props for the child block
    const innerBlocksProps = useInnerBlocksProps(blockProps);  // Using blockProps for inner block props

    // Correctly define style as an object
    const style = {
        maxWidth: maxWidth, 
    };

    const handleExpandVerticalChange = (value) => {
        setAttributes({ expandVertical: value });
    };


    return (
        <>
            {/* Inspector Controls for maxWidth */}
            <InspectorControls>
                <PanelBody title={__('Max Width Settings', 'lcp')} initialOpen={true}>
                    <div className="max-width-settings">
                        {/* UnitControl to adjust maxWidth value */}
                        <UnitControl
                            onChange={handleMaxWidthChange} // Function to handle change
                            value={maxWidth} // Current value of maxWidth
                            defaultUnit="px" // Optional: default unit for UnitControl
                        />
                        <ToggleControl
                            label={__('Enable Vertical Expansion', 'lcp')}
                            checked={expandVertical} // Bind to expandVertical attribute
                            onChange={handleExpandVerticalChange} // Function to update expandVertical
                        />
                    </div>
                </PanelBody>
            </InspectorControls>

            {/* Main block content */}
            <div {...innerBlocksProps} id="lcp-main-container" style={{minHeight:'200px'}}>


                <InnerBlocks {...innerBlocksProps} />
            </div>
        </>
    );
}
