(function(){var m=document&&document.currentScript&&document.currentScript.src;(window.webpackJsonpruntime=window.webpackJsonpruntime||[]).push([[17],{iThW:function(T,a,e){"use strict";e.r(a),e.d(a,"init",function(){return d}),e.d(a,"changeState",function(){return u});var S=e("yXPU"),c=e.n(S),l=e("ddYX");const o={};function d(r){return Array.from(document.querySelectorAll(".dmLoginBar")).forEach(i=>{o[i.id]&&o[i.id].removeEventListeners(),o[i.id]=new h({container:i})}),o[(r||{}).id]||{}}function u(r,t){o[r].changeState(t)}class h{constructor({container:t}){this.STATES={empty:{},loginButton:{},profileBar:{}},this.updateText=({state:i,element:n,text:s})=>{this.STATES[i][n].textContent=s,n==="memberNameSpan"&&this.STATES[i][n].setAttribute("data-label",s)},this.container=t,this.bindMethods(),this.initStates()}changeState(t){this.hideAll(),this.STATES[t].div.style.display="flex",this.container.setAttribute("data-showstate",t)}hideAll(){for(const t in this.STATES)this.STATES[t].hasOwnProperty("div")&&this.STATES[t].div!==null&&(this.STATES[t].div.style.display="none")}hideMyAccountLink(){const{myAccountLink:t}=this.STATES.profileBar;t&&(t.style.display="none")}bindMethods(){this.changeState=this.changeState.bind(this),this.hideAll=this.hideAll.bind(this),this.initStates=this.initStates.bind(this),this.initInitialState=this.initInitialState.bind(this)}initStates(){this.initEmptyState(),this.initLoginButtonState(),this.initProfileBarState(),this.initInitialState()}initInitialState(){var t=this;return c()(function*(){t.changeState("empty");try{const i=yield window.dmAPI.getLoggedInMember();t.updateText({state:"profileBar",element:"memberNameSpan",text:`${i.memberInfo.firstname} ${i.memberInfo.lastname}`}),t.changeState("profileBar");const{subscriptions:n}=i;!!(n&&n.totalCount)||t.hideMyAccountLink()}catch(i){t.changeState("loginButton")}})()}initEmptyState(){this.STATES.empty.div=this.container.querySelector(".empty-state")}initLoginButtonState(){this.STATES.loginButton.div=this.container.querySelector(".login-button-state")}handleClickMyAccount(){window.location.assign(`${window.location.pathname}#/dashboard`)}handleClickLogout(){return c()(function*(){try{yield fetch("/rts/auth/public/users/logout",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"}}),window.location.reload()}catch(t){yield Object(l.b)({logLevel:l.a.WARN,dataString:{message:"Error logging out a user",error:t}})}})()}initProfileBarState(){const t=this.container.querySelector(".profile-bar-state");this.STATES.profileBar.div=t,this.STATES.profileBar.memberNameSpan=t.querySelector("#member-name"),this.STATES.profileBar.logoutLink=t.querySelector(".logout-link"),this.STATES.profileBar.myAccountLink=t.querySelector(".my-account-link"),this.STATES.profileBar.myAccountLink.addEventListener("click",this.handleClickMyAccount),this.STATES.profileBar.logoutLink.addEventListener("click",this.handleClickLogout)}removeEventListeners(){this.STATES.profileBar.logoutLink.removeEventListener("click",this.handleClickLogout)}}h.displayName="LoginBar"}}])})();
