import{a as c,b as _,h as S}from"./chunk-BBRRCYIK.js";import{a}from"./chunk-CM25G6VJ.js";import{a as l}from"./chunk-WSL3XVPI.js";import{m as n}from"./chunk-ALPCJSJV.js";import{a as A}from"./chunk-E65DJUZB.js";import{f as d,u as f}from"./chunk-IQZCMWOL.js";import{$ as o,K as r,da as p,ja as s,ka as m}from"./chunk-AO7NUUXN.js";import{a as u}from"./chunk-K4ALXBGI.js";var w=["/product-receipt-view","/auth/restore-password","/auth/sign-up"];var g=(()=>{class i{constructor(t){this._http=t}signIn(t,e){return this._http.post("/api/auth",{login:t,password:e})}signUp(t){return this._http.post("/api/user",t)}isUserExist(t){return this._http.get(`/api/user/${t}/exist`)}sendPhoneCode(t){return this._http.post(`/api/phone/${t}/confirmation-code`,{})}restorePassword(t,e){return this._http.post(`/api/user/${t}/restore-password`,u({},e))}refreshToken(t){return this._http.post(l,t,{headers:A})}static{this.\u0275fac=function(e){return new(e||i)(s(d))}}static{this.\u0275prov=p({token:i,factory:i.\u0275fac})}}return i})();var L=(()=>{class i{constructor(t,e,h){this._authServiceApi=t,this._store=e,this._router=h,this._isAuth$=m(n).select(S.isAuthenticated)}initAuthSub(){this._isAuth$.subscribe(t=>{location.pathname&&location.pathname!=="/"&&w.some(e=>location.pathname.startsWith(e))||t||this._router.navigate(["/auth"])})}login(t,e){return this._authServiceApi.signIn(t,e).pipe(o(h=>{this._store.dispatch(new c(h)).pipe(r(1)).subscribe(()=>this._router.navigate(["/employee"]))}),r(1))}register(t,e){return this._authServiceApi.signUp(this._toSignUpModel(t)).pipe(o(()=>{e||this.login(a(t.phone),t.password).subscribe()}),r(1))}sendCode(t){return this._authServiceApi.sendPhoneCode(t).pipe(r(1))}isUserExist(t){return this._authServiceApi.isUserExist(t).pipe(r(1))}refreshToken(t){return this._authServiceApi.refreshToken(t).pipe(o(e=>{this._store.dispatch(new c(e)).pipe(r(1)).subscribe({})}),r(1))}restorePassword(t){let e={password:t.password,phoneConfirmationCode:t.code};return this._authServiceApi.restorePassword(a(t.phone),e).pipe(r(1))}logout(){this._store.dispatch(new _)}_toSignUpModel(t){return{phone:a(t.phone),phoneConfirmationCode:t.code,password:t.password,name:t.name}}static{this.\u0275fac=function(e){return new(e||i)(s(g),s(n),s(f))}}static{this.\u0275prov=p({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();export{g as a,L as b};
