import{a as O}from"./chunk-DM34UTHR.js";import{e as f}from"./chunk-XZELSHJP.js";import{c as v}from"./chunk-JQJV7TYV.js";import{f as b}from"./chunk-YM543BQE.js";import{c as S,f as h,ga as n,la as a,n as d}from"./chunk-NW2U37DI.js";import{h as y}from"./chunk-TWZW5B45.js";var u="admin_session_timer",g=(()=>{class e{constructor(){this.timerSubject=new h,this.innertimerSubject=new h}startTimer(t){t&&(this.timer=t,this.stopTimer(),this.timerSubscription=setInterval(()=>{let i=localStorage.getItem(u);if(i){let{timer:r}=JSON.parse(i);r>this.timer&&(this.stopInnerTimer(),this.timer=r)}this.timerSubject.next(this.timer),this.timer>0&&(this.timer--,this.stopInnerTimer(),this.updateStorage())},1e3))}startInnerTimer(t){this.innerTimer=t,this.stopInnerTimer(),this.innertimerSubscription=setInterval(()=>{this.innertimerSubject.next(this.innerTimer),this.innerTimer>0&&(this.innerTimer--,this.updateStorage())},1e3)}resetTimer(t){this.stopTimer(),this.stopInnerTimer(),this.innerTimer=0,this.startTimer(t),this.updateStorage()}stopTimer(){clearInterval(this.timerSubscription)}stopInnerTimer(){clearInterval(this.innertimerSubscription)}updateStorage(){let t={timer:this.timer,innerTimer:this.innerTimer||60};localStorage.setItem(u,JSON.stringify(t))}getTimerObservable(){return this.timerSubject.asObservable()}getInnerTimerObservable(){return this.innertimerSubject.asObservable()}getSecondaryTimer(){return this.innerTimer}loadStateFromStorage(){let t=localStorage.getItem(u);if(t){let{timer:i,innerTimer:r}=JSON.parse(t);this.timer=i,this.innerTimer=r}}static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275prov=n({token:e,factory:e.\u0275fac,providedIn:"root"})}}return e})();var o=y(O());var I=(()=>{class e{constructor(){}setSharedData(t){this.sharedData=t}getSharedData(){return this.sharedData}static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275prov=n({token:e,factory:e.\u0275fac,providedIn:"root"})}}return e})();var J=(()=>{class e{constructor(t,i,r,m,s){this.timerService=t,this.router=i,this.adminService=r,this.translatePipe=m,this.adminDataService=s,this.timerService.loadStateFromStorage()}canActivate(t,i){let r=this.adminDataService.getSharedData();if(r?.admin_users_inactive_auto_logout=="on"||r?.admin_users_inactive_auto_logout==!0){let m=Number(r?.admin_users_inactive_auto_logout_time)*60;return this.timerService.startTimer(m),new S(s=>{let j=this.timerService.getTimerObservable().subscribe(_=>{_===0?o.default.fire({title:'<h4 class="fw-semibold mb-1">'+this.translatePipe.transform("You have been inactive since last")+r?.admin_users_inactive_auto_logout_time+this.translatePipe.transform("minutes. Do you wish to stay?")+"</h4>",icon:"warning",allowOutsideClick:!1,showConfirmButton:!0,confirmButtonText:this.translatePipe.transform("Stay Signed In"),didOpen:()=>{this.timerService.stopTimer(),this.timerService.startInnerTimer(60);let c=this.timerService.getInnerTimerObservable().subscribe(l=>{let p=localStorage.getItem("admin_session_timer");if(p){let{timer:w}=JSON.parse(p);w>0&&(this.timerService.stopInnerTimer(),c.unsubscribe(),o.default.close())}this.innerTimerValue='<span class="d-block text-muted fw-normal">'+this.translatePipe.transform("Your session will be timed out in")+'<h3 class="countdown mb-0">'+l+"</h3>"+this.translatePipe.transform("seconds"),+"</span>",o.default.update({html:this.innerTimerValue}),l===0&&(j.unsubscribe(),c.unsubscribe(),this.timerService.stopInnerTimer(),this.Adminlogout(),o.default.close())})}}).then(c=>{c.isConfirmed&&(this.timerService.resetTimer(m),this.timerService.stopInnerTimer(),s.next(!0),s.complete())}):(s.next(!0),s.complete())})})}return d(!0)}Adminlogout(){let t={};this.adminLogout$=this.adminService.AdminLogout(t).subscribe({next:i=>{localStorage.clear(),this.router.navigate(["/admin/login"]).then(()=>{}),history.pushState(null,""),this.adminLogout$.unsubscribe()}})}static{this.\u0275fac=function(i){return new(i||e)(a(g),a(f),a(b),a(v),a(I))}}static{this.\u0275prov=n({token:e,factory:e.\u0275fac,providedIn:"root"})}}return e})();export{I as a,g as b,J as c};
