(function () {
	var cfg = typeof window.spFreemiusGate === 'object' ? window.spFreemiusGate : {};
	if (cfg.isPremium) {
		return;
	}

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

	function closeModal() {
		var el = document.getElementById('bspp-fs-upgrade-modal');
		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;
		}
		var row = t.closest('.sp-pro-locked-row');
		if (row) {
			e.preventDefault();
			openModal();
		}
	});

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