(function () {
	var cfg = typeof window.spFreemiusGateFront === 'object' ? window.spFreemiusGateFront : {};

	function openModal() {
		var el = document.getElementById('sp-fs-upgrade-modal-front');
		if (!el) {
			return;
		}
		el.removeAttribute('hidden');
		el.setAttribute('aria-hidden', 'false');
	}

	function closeModal() {
		var el = document.getElementById('sp-fs-upgrade-modal-front');
		if (!el) {
			return;
		}
		el.setAttribute('hidden', 'hidden');
		el.setAttribute('aria-hidden', 'true');
	}

	document.addEventListener('click', function (e) {
		var t = e.target;
		if (!t || !t.closest) {
			return;
		}
		if (t.closest('[data-sp-fs-close]')) {
			closeModal();
			return;
		}
		if (t.closest('.sp-paywall-pro-gate')) {
			e.preventDefault();
			openModal();
		}
	});

	document.addEventListener('keydown', function (e) {
		if (e.key === 'Escape') {
			closeModal();
		}
	});
})();
