( function ( blocks, element, blockEditor, components, i18n ) {
	const { registerBlockType } = blocks;
	const { createElement: el } = element;
	const { InspectorControls, useBlockProps } = blockEditor;
	const { PanelBody, TextControl } = components;
	const { __ } = i18n;

	if ( ! registerBlockType ) {
		return;
	}

	registerBlockType( 'shc4wc/payment-link', {
		apiVersion: 2,
		title: __( 'Square Payment Link', 'payments-connect-square' ),
		description: __(
			'Add a button that sends visitors to Square Hosted Checkout to pay a fixed amount.',
			'payments-connect-square'
		),
		category: 'widgets',
		icon: 'money-alt',
		keywords: [
			__( 'square', 'payments-connect-square' ),
			__( 'payment', 'payments-connect-square' ),
			__( 'pay', 'payments-connect-square' ),
			__( 'checkout', 'payments-connect-square' ),
		],
		supports: {
			html: false,
		},
		edit: function ( props ) {
			const { attributes, setAttributes } = props;
			const blockProps = useBlockProps( { className: 'shc4wc-payment-link-block' } );

			return el(
				'div',
				blockProps,
				el(
					InspectorControls,
					null,
					el(
						PanelBody,
						{ title: __( 'Square Payment Link', 'payments-connect-square' ), initialOpen: true },
						el( TextControl, {
							label: __( 'Amount', 'payments-connect-square' ),
							help: __( 'Example: 25.00', 'payments-connect-square' ),
							value: attributes.amount || '',
							onChange: function ( value ) {
								setAttributes( { amount: value } );
							},
						} ),
						el( TextControl, {
							label: __( 'Button label', 'payments-connect-square' ),
							value: attributes.label || '',
							onChange: function ( value ) {
								setAttributes( { label: value } );
							},
						} ),
						el( TextControl, {
							label: __( 'Description (optional)', 'payments-connect-square' ),
							value: attributes.description || '',
							onChange: function ( value ) {
								setAttributes( { description: value } );
							},
						} ),
						el( TextControl, {
							label: __( 'Currency (optional)', 'payments-connect-square' ),
							help: __( 'Leave empty to use store currency or USD.', 'payments-connect-square' ),
							value: attributes.currency || '',
							onChange: function ( value ) {
								setAttributes( { currency: value } );
							},
						} )
					)
				),
				el(
					'a',
					{
						className: 'button shc4wc-payment-link-button',
						href: '#',
						onClick: function ( event ) {
							event.preventDefault();
						},
					},
					attributes.label || __( 'Pay Now', 'payments-connect-square' )
				),
				el(
					'p',
					{ className: 'description' },
					__( 'Preview only — visitors are redirected to Square Hosted Checkout.', 'payments-connect-square' )
				)
			);
		},
		save: function () {
			return null;
		},
	} );
} )( window.wp.blocks, window.wp.element, window.wp.blockEditor, window.wp.components, window.wp.i18n );
