import{a as v}from"./chunk-43XOJ7D3.js";import{b as u}from"./chunk-VS2SSE5T.js";import{a as f,b}from"./chunk-5GJ7UEF2.js";import{a as d}from"./chunk-FTPWLRQ4.js";import{a as k}from"./chunk-ZAOXB7JK.js";import{o as p}from"./chunk-GW2OL5S3.js";import{a as P}from"./chunk-P5XIDEFS.js";import{a as _}from"./chunk-PDYJ5OYY.js";import{d as S,i as w,u as A}from"./chunk-CO3WTSA4.js";import{D as g,I as i,Z as a,ea as c,ja as o,k as m,ka as h}from"./chunk-DYUFV4HF.js";import{a as l}from"./chunk-B7YGBANW.js";var I=["/product-receipt-view","/auth/restore-password","/auth/sign-up","/showcase"];var E=(()=>{let r=class r{constructor(t){this._http=t,this._store=h(p),this._offlineMode=h(v)}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`,l({},e))}refreshToken(t){return this._http.post(k,t,{headers:P})}logout(t){if(this._offlineMode.isOfflineMode)return m(void 0);let e=new S().append(_.SkipError,"skipError").append(_.ActAsGet,"true");return this._http.post("/api/auth/logout",t,{headers:e}).pipe(g(()=>m(void 0)))}changePassword(t){return this._http.post("/api/user/change-password",t)}};r.\u0275fac=function(e){return new(e||r)(o(w))},r.\u0275prov=c({token:r,factory:r.\u0275fac});let s=r;return s})();var Y=(()=>{let r=class r{constructor(t,e,n){this._authServiceApi=t,this._store=e,this._router=n,this._isAuth$=h(p).select(u.isAuthenticated),this._tokens=this._store.selectSignal(u.tokens),this._userId=this._store.selectSignal(u.userId)}initAuthSub(){this._isAuth$.subscribe(t=>{location.pathname&&location.pathname!=="/"&&I.some(e=>location.pathname.startsWith(e))||t||this._router.navigate(["/auth"])})}login(t,e,n){return this._authServiceApi.signIn(t,e).pipe(a(j=>{this._store.dispatch(new f(j)).pipe(i(1)).subscribe(()=>{this._router.navigate(["/employee/company"],{queryParams:{id:n}})})}),i(1))}register(t,e=!1,n){return this._authServiceApi.signUp(this._toSignUpModel(t)).pipe(a(()=>{e||this.login(d(t.phone),t.password,n).subscribe()}),i(1))}sendCode(t){return this._authServiceApi.sendPhoneCode(t).pipe(i(1))}isUserExist(t){return this._authServiceApi.isUserExist(t).pipe(i(1))}refreshToken(t){return this._authServiceApi.refreshToken(t).pipe(a(e=>{this._store.dispatch(new f(e)).pipe(i(1)).subscribe({})}),i(1))}restorePassword(t){let e={password:t.password,phoneConfirmationCode:t.code};return this._authServiceApi.restorePassword(d(t.phone),e).pipe(i(1))}logout(){let t={refreshToken:this._tokens()?.refreshToken??"",userId:this._userId()??""};return this._store.dispatch(new b).pipe(a(()=>{this._authServiceApi.logout(t).subscribe()}))}changePassword(t){return this._authServiceApi.changePassword(t)}_toSignUpModel(t){return{phone:d(t.phone),phoneConfirmationCode:t.code,password:t.password,name:t.name}}};r.\u0275fac=function(e){return new(e||r)(o(E),o(p),o(A))},r.\u0275prov=c({token:r,factory:r.\u0275fac,providedIn:"root"});let s=r;return s})();export{E as a,Y as b};
//# sourceMappingURL=chunk-OKQRNSE4.js.map
