( function () {
	var wc = window.wc || {};
	var registry = wc.wcBlocksRegistry || wc.blocksRegistry;
	if ( ! registry || ! registry.registerPaymentMethod ) {
		return;
	}
	var settingsApi = ( wc.wcSettings && wc.wcSettings.getSetting ) ? wc.wcSettings : ( window.wcSettings || null );
	var getSetting = settingsApi && settingsApi.getSetting ? settingsApi.getSetting : function () { return {}; };

	var settings = getSetting( 'flexilay_data', {} ) || {};
	var title = settings.title || 'FlexiLay Lay-buy (Pay Before Delivery)';
	var description = settings.description || '';

	var el = ( window.wp && window.wp.element && window.wp.element.createElement ) ? window.wp.element.createElement : null;
	if ( ! el ) {
		return;
	}

	var Content = function () {
		return el(
			'div',
			{ className: 'wc-block-components-payment-method__description' },
			description
		);
	};

	registry.registerPaymentMethod( {
		name: 'flexilay',
		label: title,
		ariaLabel: title,
		content: el( Content, null ),
		edit: el( Content, null ),
		editor: el( Content, null ),
		canMakePayment: function () { return true; },
		supports: { features: [ 'products' ] },
	} );

	window.__flexilayBlocksRegistered = true;
} )();
