import{I as u,Sa as r,fb as d,hb as g,ib as a,p as i,t as n,x as s}from"./chunk-FSZJUE3R.js";var l=class o{api=s(g);storage=s(d);storageKey="taxitaxi_auth";auth=u(this.storage.get(this.storageKey));isAuthenticated=r(()=>this.auth()!==null);userId=r(()=>this.auth()?.id??null);username=r(()=>this.auth()?.username??null);role=r(()=>this.auth()?.role??null);isAdmin=r(()=>this.auth()?.role==="ADMIN");token(){return this.auth()?.token??null}login(e,t){return this.api.post(a.users.login,{username:e,password:t}).pipe(i(h=>this.persist(h)))}refresh(){let e=this.auth();return this.api.post(a.users.refresh,{id:e?.id,token:e?.token}).pipe(i(t=>this.persist(t)))}logout(){this.auth.set(null),this.storage.remove(this.storageKey)}persist(e){let t={id:e.id,username:e.username,role:e.role,token:e.token};this.auth.set(t),this.storage.set(this.storageKey,t)}static \u0275fac=function(t){return new(t||o)};static \u0275prov=n({token:o,factory:o.\u0275fac,providedIn:"root"})};export{l as a};
