(function ($) {
	const params = new URLSearchParams(window.location.search);
	const error = params.get('pixelio_expired');
	if (!error) return;

	const messageMap = {
		'1': 'Your recovery link is invalid/expired or your cart is empty.',
		default: 'Something went wrong.'
	};

	const message = messageMap[error] || messageMap.default;

	function renderNotice() {

		const container = document.querySelector('.wc-block-components-notices');

		if (!container) return false;

		const notice = document.createElement('div');
		notice.className = 'wc-block-components-notice-banner is-error';
		notice.setAttribute('role', 'alert');

		notice.innerHTML = `
			<div class="wc-block-components-notice-banner__content">
				${message}
			</div>
		`;

		container.prepend(notice);

		return true;
	}

	// Blocks parfois load async → retry léger
	let attempts = 0;

	const interval = setInterval(() => {

		attempts++;

		if (renderNotice() || attempts > 20) {
			clearInterval(interval);
		}

	}, 200);

	// clean URL (UX propre)
	params.delete('pixelio_expired');
	const newUrl = window.location.pathname + (params.toString() ? '?' + params.toString() : '');
	window.history.replaceState({}, document.title, newUrl);

})();
