(function() {
	var VIEW_TO_FEATURE = {
		event_analytics_monitoring: 'itsi_event_analytics',
		event_analytics_audit: 'itsi_event_analytics'
	};
	var currentUrl = window.location.pathname;
	var requestedView = currentUrl.substring(currentUrl.lastIndexOf('/') + 1).replace('_deprecated', '');
	var requestedFeature = VIEW_TO_FEATURE[requestedView];
	if (window.$C) {
		var fullUrl = window.$C.SPLUNKD_PATH + '/servicesNS/nobody/SA-ITOA/feature_flagging/features';
		fetch(fullUrl)
			.then(response => response.json())
			.then(data => {
				if (data && data[requestedFeature] === false) {
					// redirect using requestedView as license upgrade uses page url to render correctly
					var redirectUrl = `${window.$C.MRSPARKLE_ROOT_PATH || ''}/${window.$C.LOCALE}/app/itsi/license_upgrade?feature=${requestedView}`;
					window.location.replace(redirectUrl);
				}
			})
			.catch((error) => {
				console.error('Error:', error);
			});
	}
})();