/**
 * Donation Form Block - Editor Registration
 */
(function() {
	var el = wp.element.createElement;
	var registerBlockType = wp.blocks.registerBlockType;
	var ServerSideRender = wp.serverSideRender;
	var InspectorControls = wp.blockEditor.InspectorControls;
	var PanelBody = wp.components.PanelBody;
	var TextControl = wp.components.TextControl;
	var Fragment = wp.element.Fragment;
	var __ = wp.i18n.__;

	registerBlockType('ambassadorhub/donation-form', {
		edit: function (props) {
			var attributes = props.attributes;
			var setAttributes = props.setAttributes;
			var blockProps = wp.blockEditor.useBlockProps();

			return el(
				'div',
				blockProps,
				el(
					InspectorControls,
					{},
					el( PanelBody, { title: __( 'Display', 'ambassadorhub' ), initialOpen: true },
						el( TextControl, {
							label:    __( 'Title', 'ambassadorhub' ),
							value:    attributes.title || '',
							help:     __( 'Optional heading shown above the donation form.', 'ambassadorhub' ),
							onChange: function ( v ) { setAttributes( { title: v } ); },
						} )
					)
				),
				el(ServerSideRender, {
					block: 'ambassadorhub/donation-form',
					attributes: attributes
				})
			);
		},
		save: function () {
			return null; // Server-side rendered
		}
	});
})();
