( function() {
	const wcSettings = ( window.wc && window.wc.wcSettings ) || window.wcSettings;
	const wcBlocksRegistry = ( window.wc && window.wc.wcBlocksRegistry ) || window.wcBlocksRegistry;
	const decodeEntities =
		window.wp &&
		window.wp.htmlEntities &&
		typeof window.wp.htmlEntities.decodeEntities === 'function'
			? window.wp.htmlEntities.decodeEntities
			: function( value ) {
				return value;
			};

	if ( ! wcSettings || ! wcBlocksRegistry || ! window.wp || ! window.wp.element ) {
		return;
	}

	const settings = wcSettings.getSetting( 'shc4wc_data', {} );
	const label = decodeEntities( settings.title || 'Pay with Square' );

	const Content = () => {
		return window.wp.element.createElement(
			'div',
			null,
			decodeEntities( settings.description || 'You will be redirected to Square secure hosted checkout (WPPayments).' )
		);
	};

	wcBlocksRegistry.registerPaymentMethod( {
		name: 'shc4wc',
		label: window.wp.element.createElement( 'span', null, label ),
		ariaLabel: label,
		content: window.wp.element.createElement( Content, null ),
		edit: window.wp.element.createElement( Content, null ),
		canMakePayment: function() {
			return true;
		},
		supports: {
			features: settings.supports || [ 'products' ],
		},
	} );
} )();
