import{h as o,i as h}from"./chunk-HMHHBN2H.js";import{D as g,E as u}from"./chunk-DQXXLIFV.js";import{da as n,fd as l,ia as s}from"./chunk-LU6Q5ONP.js";l();h();u();var S=(()=>{class a{get languageId(){return this._languageId}constructor(e,i){this.authService=e,this.localeService=i,this.LOCALE_STORAGE_KEY="paw-locale",this.LOCALE_UPDATE_STORAGE_KEY="paw-locale-update",this._languageId=null,this.storageListener=t=>{if(t.key===this.getStorageKey(this.LOCALE_UPDATE_STORAGE_KEY)&&t.newValue)try{let r=JSON.parse(t.newValue);r&&r.languageId&&this.setLanguage(r.languageId,!1)}catch{}}}init(){this.registerMultitabLanguageChanged(),this.renewLanguage()}destroy(){this.resetLanguage(),window.removeEventListener("storage",this.storageListener)}setLanguage(e,i=!0){if(this._languageId===e)return;this._languageId=e;let t=this.getStorageKey();t&&(localStorage.setItem(t,e),i&&localStorage.setItem(this.getStorageKey(this.LOCALE_UPDATE_STORAGE_KEY),JSON.stringify({languageId:e,date:Date.now()}))),this.localeService.loadTranslations(this._languageId,!0)}renewLanguage(){let e=this.getStorageKey();e&&(this._languageId=localStorage.getItem(e)??null)}resetLanguage(){this._languageId=null,this.localeService.loadTranslations(this.localeService.defaultLocale,!0)}getStorageKey(e=this.LOCALE_STORAGE_KEY){return this.authService.authUser?`${e}-${this.authService.authUser.domain}-${this.authService.authUser.username}`:null}registerMultitabLanguageChanged(){window.addEventListener("storage",this.storageListener)}static{this.\u0275fac=function(i){return new(i||a)(s(o),s(g))}}static{this.\u0275prov=n({token:a,factory:a.\u0275fac,providedIn:"root"})}}return a})();export{S as a};
