import{R as b}from"./Root-rl66e6VO.js";import{aH as c}from"./index-D02r7Zsc.js";class I extends b{constructor(){super()}async setData(t,s=!1){if(s)switch(s){case"barcodeinfo":let e=await this.get("ws").getAccountInfos(t);this.set("accountInfos",e);return;case"cart":let v=this.get("ws").getCartContent(t),A=this.get("ws").getAccountInfos(t),p=this.get("ws").getListOfCurrentLoans(t);await Promise.all([v,A,p]).then(n=>{this.set("cart",n[0]),this.set("accountInfos",n[1]),this.set("currentLoans",n[2])});return;case"loans":let y=this.get("ws").getListOfCurrentLoans(t),m=this.get("ws").getListOfDelayedLoans(t),S=this.get("ws").getListOfReservations(t),d=this.get("ws").getListOfPreviousLoans(t),C=this.get("ws").getCartContent(t),O=this.get("ws").getAccountInfos(t);await Promise.all([y,m,S,d,C,O]).then(n=>{this.set("currentLoans",n[0]),this.set("delayedLoans",n[1]),this.set("reservations",n[2]),this.set("previousLoans",n[3]),this.set("cart",n[4]),this.set("accountInfos",n[5])});return;case"account/edit":let x=await this.get("ws").getAccountInfos(t);this.set("accountInfos",x);return;default:return}let a=this.get("ws").getListOfCurrentLoans(t),i=this.get("ws").getListOfDelayedLoans(t),o=this.get("ws").getListOfReservations(t),r=this.get("ws").getListOfPreviousLoans(t),l=this.get("ws").getCartContent(t),h=this.get("ws").getAccountInfos(t),g=this.get("ws").getShelvesList(t),u=this.get("ws").getReadingLists(t),f=this.get("ws").getDSIPublicAlerts(t),w=this.get("ws").getDSIPrivateAlerts(t),L=this.get("ws").getUpcomingAnimations(t);await Promise.all([a,i,o,r,l,h,g,u,f,w,L]).then(e=>{this.set("currentLoans",e[0]),this.set("delayedLoans",e[1]),this.set("reservations",e[2]),this.set("previousLoans",e[3]),this.set("cart",e[4]),this.set("accountInfos",e[5]),this.set("userId",e[5].id),this.set("shelves",e[6]),this.setDefaultLocation(e[5].location_id),this.set("readinglists",e[7]),this.set("alerts",e[8]),this.set("privateAlerts",e[9]),this.set("upcomingAnimations",e[10])}),this.set("data_set",!0)}async setDefaultLocation(t){localStorage.getItem("userDefaultLocation")||localStorage.setItem("userDefaultLocation",JSON.stringify(t))}async login(t=null,s=null,a=!1){if(t!==null||s!==null)var i={login:t,password:s},o=await this.get("ws").login(t,s);else if(localStorage.getItem("mainAccount")){try{var i=this.getUserInfos(localStorage.getItem("mainAccount"))}catch{return!1}var o=await this.get("ws").login(i.login,i.password)}if(a)return o;if(typeof o=="string"){this.set("sessionId",o);let r=this.encryptUserInfos(i.login,i.password,o);return localStorage.setItem("mainAccount",r),await this.setData(this.get("sessionId")),!0}else return localStorage.removeItem("mainAccount"),!1}getUserInfos(t){var s=c.AES.decrypt(t,this.getConfig().key),a=JSON.parse(s.toString(c.enc.Utf8));return{login:atob(a.login),password:atob(a.password),sessionId:a.sessionId?atob(a.sessionId):""}}encryptUserInfos(t,s,a=!1){if(a)var i=JSON.stringify({login:btoa(t),password:btoa(s),sessionId:btoa(a)});else var i=JSON.stringify({login:btoa(t),password:btoa(s)});var o=c.AES.encrypt(i,this.getConfig().key).toString();return o}async checkExtAuth(){if(this.get("checkExtAuth")===void 0){var t=await this.get("ws").checkExtAuth();t.ext_auth?this.set("checkExtAuth",t.ext_auth):this.set("checkExtAuth",!1)}return this.get("checkExtAuth")}}export{I as default};
