(() => {
    'use strict';
    const i18n = wp.i18n,
        plugins = wp.plugins,
        editPost = wp.editPost,
        components = wp.components;

    var HeaderTemplateSelect = (0, wp.data.withSelect)(function (select) {
        return {
            selectedTemplate: select('core/editor').getEditedPostAttribute('meta').eac_theme_builder_template_siteheader
        }
    })(function (props) {
        var selectedTemplate = props.selectedTemplate,
            onUpdate = props.onUpdate;

        return React.createElement(components.SelectControl, {
            label: (0, i18n.__)('EAC header template', 'eac-components'),
            value: selectedTemplate,
            onChange: onUpdate,
            className: 'editor-page-attributes__template',
            options: elementorSiteBuilderData.headerTemplates
        })
    });

    const HeaderTemplateDispatch = (0, wp.data.withDispatch)(function (dispatch) {
        return {
            onUpdate: function (template) {
                dispatch('core/editor').editPost({
                    meta: {
                        eac_theme_builder_template_siteheader: template ? template : 'inherit'
                    }
                })
            }
        }
    })(HeaderTemplateSelect);

    var FooterTemplateSelect = (0, wp.data.withSelect)(function (select) {
        return {
            selectedTemplate: select('core/editor').getEditedPostAttribute('meta').eac_theme_builder_template_sitefooter
        }
    })(function (props) {
        var selectedTemplate = props.selectedTemplate,
            onUpdate = props.onUpdate;
        return React.createElement(components.SelectControl, {
            label: (0, i18n.__)('EAC footer template', 'eac-components'),
            value: selectedTemplate,
            onChange: onUpdate,
            className: 'editor-page-attributes__template',
            options: elementorSiteBuilderData.footerTemplates
        })
    });

    const FooterTemplateDispatch = (0, wp.data.withDispatch)(function (dispatch) {
        return {
            onUpdate: function (template) {
				dispatch('core/editor').editPost({
					meta: {
						eac_theme_builder_template_sitefooter: template ? template : 'inherit'
					}
				});
            }
        }
    })(FooterTemplateSelect);

	(0, plugins.registerPlugin)('eac-theme-builder-plugin', {
		icon: 'layout', // Icône pour symboliser un modèle
		render: function () {
			return React.createElement(editPost.PluginSidebar, {
				name: 'eac-theme-builder-template-settings',
				title: (0, i18n.__)('EAC template settings', 'eac-components')
			}, React.createElement(components.PanelBody, null, React.createElement('p', null, (0, i18n.__)('"Inherit" will display the template assigned for "Entire Site". "Theme Default" will display the template from the current theme.', 'eac-components')), React.createElement(HeaderTemplateDispatch, null), React.createElement(FooterTemplateDispatch, null)))
		}
	})

})();