wp.hooks.addFilter( 'blocks.registerBlockType', 'gallery-helper/add-attributes', function( settings, name ) {
    if ( name === 'core/gallery' ) {
        settings.attributes = {
            ...settings.attributes,
            enableLightbox: {
                type: 'boolean',
                default: false,
            },
            slideshowMode: {
                type: 'string',
                default: 'manual',
            },
        };
    }
    return settings;
} );

const withInspectorControls = wp.compose.createHigherOrderComponent( ( BlockEdit ) => {
    return ( props ) => {
        if ( props.name !== 'core/gallery' ) {
            return wp.element.createElement( BlockEdit, props );
        }
        return wp.element.createElement( wp.element.Fragment, {},
            wp.element.createElement( BlockEdit, props ),
            wp.element.createElement( wp.blockEditor.InspectorControls, {},
                wp.element.createElement( wp.components.PanelBody, { title: "Lightbox Settings" },
                    wp.element.createElement( wp.components.ToggleControl, {
                        label: "Enable Lightbox",
                        checked: props.attributes.enableLightbox,
                        onChange: ( value ) => props.setAttributes( { enableLightbox: value } )
                    } ),
                    props.attributes.enableLightbox && wp.element.createElement( wp.components.SelectControl, {
                        label: "Slideshow Mode",
                        value: props.attributes.slideshowMode,
                        options: [
                            { label: 'Manual', value: 'manual' },
                            { label: 'Automatic', value: 'auto' },
                        ],
                        onChange: ( value ) => props.setAttributes( { slideshowMode: value } )
                    } )
                )
            )
        );
    };
}, 'withInspectorControls' );

wp.hooks.addFilter( 'editor.BlockEdit', 'gallery-helper/with-inspector-controls', withInspectorControls );
