class Alerts{splitLongAlerts(){var n=this;this.$alertsBoxBody.children().each(function(t){var r=n.$alertsBox.get(0).clientHeight,s=$(this).attr("data-type"),e=$(this).text(),l="",e=e.split(" "),o=[],a="",i=0;e.forEach(function(e){a+=a?" "+e:e,$(".tempAlert").html(a),$(".tempAlert").height()>r&&(a=a.substring(0,a.lastIndexOf(" ")),o.push({key:i,value:a}),a=e,i++)}),o.push({key:i,value:a}),o.forEach(function(e){0<e.value.length&&(l+='<li id="alertsLi'+t+"_"+e.key+'" data-type="'+s+'">'+e.value+"</li>")}),$(this).replaceWith(replaceUrlsWithLinks(l))})}hashCode(e){for(var t=0,r=0;r<e.length;r++)t=~~((t<<5)-t+e.charCodeAt(r));return t}startEasyTicker(){$(".siteWideAlerts").easyTicker({direction:"up",easing:"swing",speed:"slow",interval:globalVars.tickerInterval,height:"auto",visible:1,mousePause:1,controls:{up:"",down:"",toggle:"",playText:"Play",stopText:"Stop"}}),$(".siteWideAlerts").on("contentChanged",this.toggleAlertColor)}constructor(){this.cycleTimeForAllAlerts=0,this.$alertsBox=$("#alertsBox"),this.$alertsBoxBody=this.$alertsBox.find("ul"),this.forceAlertRefresh=()=>{this.getAlerts(this.updateAlerts,this.updateGlobalEmergencyPopup)},this.alertsCheckedOnPageLoad=!1,this.getAlerts=(r,s)=>{var e=Cookies.get("_culture")?Cookies.get("_culture"):"";$.ajax({url:"/Alert/GetUpdatedAlerts?lang="+e,dataType:"json"}).done(e=>{e.alerts&&r(e.alerts);let t=!1;0!==e.emergencyAlertHash?($(".emergencyPopupNotification").show(),$("footer").addClass("pad45"),Cookies.get("emergencyPopup")!=e.emergencyAlertHash&&(Cookies.set("emergencyPopup",e.emergencyAlertHash,{expires:365,path:"/"}),s(),t=!0)):($("footer").removeClass("pad45"),$(".emergencyPopupNotification").hide(),Cookies.remove("emergencyPopup",{path:"/"})),this.alertsCheckedOnPageLoad||t&&"none"!=$(".emergencyPopupNotification").css("display")||"True"!=resources.FeatureSlideModal||$(document).trigger("displayFeatureModal"),this.alertsCheckedOnPageLoad=!0})},this.updateAlerts=e=>{var t,r,s,l,o,a=this.$alertsBox.data("easyTicker"),i=(a&&a.stop(),this);this.$alertsBoxBody.empty(),0<e.length?"true"!=resources.UseAlertBellIcon?(t=0,r=Cookies.get("_culture"),s=Cookies.get("_region")?Cookies.get("_region"):"ALL",l=-1==(l=null!=r?r.toLowerCase():"en").indexOf("-")?l:l.split("-")[0],o='""',$.each(e,function(){var e;(!this.filterRegions||"ALL"==s||0<=this.regions.indexOf(s))&&("fr"===l?e=this.messages.messageLang2:"es"===l&&(e=this.messages.messageLang3),(e=(e=null!=e&&""!=e.message?e:this.messages.messageLang1).message)&&(o=this.highImportance?"highImportanceAlert":"","true"===resources.FloodgateAlertBarAsLink?i.$alertsBoxBody.append('<li id="alertsLi'+t+'" data-type="'+o+'"><a href="/List/Alerts">'+e+"</a></li>"):i.$alertsBoxBody.append('<li id="alertsLi'+t+'" data-type="'+o+'">'+e+"</li>")),t++)}),this.splitLongAlerts(),this.cycleTimeForAllAlerts=i.$alertsBoxBody[0].childElementCount*globalVars.tickerInterval,this.cycleTimeForAllAlerts>this.currentFetchAlertsFreqTime&&(clearInterval(this.fetchAlertsInterval),this.currentFetchAlertsFreqTime=this.cycleTimeForAllAlerts+1e3,this.fetchAlertsInterval=setInterval(()=>{this.forceAlertRefresh()},this.currentFetchAlertsFreqTime)),$("#emptyAlertLi").remove(),i.toggleAlertColor(),1<i.$alertsBoxBody.children().length&&a?a.start():i.$alertsBoxBody.append('<li id="emptyAlertLi">&nbsp;</li>')):($(".alertIcon").attr("title",resources.Alerts),$(".alertIcon .dot").show()):"true"!=resources.UseAlertBellIcon?(i.$alertsBoxBody.append('<li id="emptyAlertLi">&nbsp;</li>'),i.toggleAlertColor()):($(".alertIcon").attr("title",resources.NoAlert),$(".alertIcon .dot").hide())},this.updateGlobalEmergencyPopup=()=>{var e=Cookies.get("_culture")?Cookies.get("_culture"):"";$.ajax({url:"/Alert/GetEmergencyAlert?lang="+e,dataType:"json"}).done(e=>{$(".emergencyPopupNotification").attr("data-alert",e.content),0<e.content.length&&0==$(".modal.in").length?this.showPopup(e.content):"True"==resources.FeatureSlideModal&&$(document).trigger("displayFeatureModal")})},this.showPopup=e=>{bootbox.dialog({title:'<i style="padding-right: 5px;" class="far fa-exclamation-triangle"></i> '+resources.EmergencyAlertPopUp.toUpperCase(),onEscape:!0,className:"emergencyAlertModal",message:e})},this.toggleAlertColor=()=>{"highImportanceAlert"==this.$alertsBoxBody.children().first().data("type")?$(".scrollRow").addClass("highImportanceAlert"):$(".scrollRow").removeClass("highImportanceAlert")},this.startEasyTicker()}}$(document).ready(()=>{var r=new Alerts;r.forceAlertRefresh(),r.currentFetchAlertsFreqTime=resources.AlertRefreshInterval?parseInt(resources.AlertRefreshInterval):6e4,r.fetchAlertsInterval=setInterval(()=>{r.forceAlertRefresh()},r.currentFetchAlertsFreqTime),$(".emergencyPopupNotification").on("click",function(e){$(".emergencyPopupNotification").attr("data-alert")?r.showPopup($(".emergencyPopupNotification").attr("data-alert")):r.updateGlobalEmergencyPopup()}),$(window).on("regionChanged orientationchange",function(e,t){r.forceAlertRefresh()}),Array.from(document.querySelectorAll("[data-single-submit-form]")).forEach(e=>{let t=e.querySelector("[data-single-submit-btn]");t&&e.addEventListener("submit",()=>{$(e).validate().form()?(t.disabled=!0,t.classList.add("disabled")):$("html, body").animate({scrollTop:0},"slow")})})});
