/**
 * MenuX — Footer block editor script.
 * Vanilla JS, no build step required (same pattern as menux-menu).
 */
( function () {
	'use strict';

	if (
		! window.wp ||
		! wp.blocks ||
		! wp.element ||
		! wp.blockEditor ||
		! wp.components
	) {
		return;
	}

	var el                = wp.element.createElement;
	var Fragment          = wp.element.Fragment;
	var registerBlockType = wp.blocks.registerBlockType;
	var ServerSideRender  = wp.serverSideRender || null;
	var InspectorControls = wp.blockEditor.InspectorControls;
	var useBlockProps     = wp.blockEditor.useBlockProps;
	var PanelBody         = wp.components.PanelBody;
	var ExternalLink      = wp.components.ExternalLink;

	registerBlockType( 'giuliomax/footer', {

		edit: function ( props ) {
			var blockProps = useBlockProps();

			return el(
				Fragment,
				null,

				el(
					InspectorControls,
					null,
					el(
						PanelBody,
						{ title: 'MenuX Footer', initialOpen: true },
						el( 'p', { style: { fontSize: '12px', color: '#64748b' } },
							'Content and style are managed centrally in the Footer Builder.' ),
						el( ExternalLink,
							{ href: ( window.location.origin || '' ) + '/wp-admin/admin.php?page=menux-footer' },
							'Open Footer Builder' )
					)
				),

				el(
					'div',
					blockProps,
					ServerSideRender
						? el( ServerSideRender, { block: 'giuliomax/footer' } )
						: el( 'p', { style: { padding: '1em', opacity: '.6' } }, 'MenuX — Footer' )
				)
			);
		},

		save: function () {
			return null;
		},
	} );
} )();
