import{b as g}from"./chunk-VCKZUP7X.js";import{a as u,b as _}from"./chunk-XUSKVTJP.js";import{a as c}from"./chunk-B6U47PXC.js";import{a as w}from"./chunk-ZAOXB7JK.js";import{n as h}from"./chunk-DC6G5OHZ.js";import{a as S}from"./chunk-JUPKAJPM.js";import{i as f,u as l}from"./chunk-Z2AWIQRI.js";import{L as r,aa as n,ia as a,na as p,oa as d}from"./chunk-C2QKZJOP.js";import{a as m}from"./chunk-B7YGBANW.js";var b=["/product-receipt-view","/auth/restore-password","/auth/sign-up","/showcase"];var A=(()=>{let i=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`,m({},e))}refreshToken(t){return this._http.post(w,t,{headers:S})}};i.\u0275fac=function(e){return new(e||i)(p(f))},i.\u0275prov=a({token:i,factory:i.\u0275fac});let o=i;return o})();var O=(()=>{let i=class i{constructor(t,e,s){this._authServiceApi=t,this._store=e,this._router=s,this._isAuth$=d(h).select(g.isAuthenticated)}initAuthSub(){this._isAuth$.subscribe(t=>{location.pathname&&location.pathname!=="/"&&b.some(e=>location.pathname.startsWith(e))||t||this._router.navigate(["/auth"])})}login(t,e,s){return this._authServiceApi.signIn(t,e).pipe(n(v=>{this._store.dispatch(new u(v)).pipe(r(1)).subscribe(()=>{console.log(s),this._router.navigate(["/employee/company"],{queryParams:{id:s}})})}),r(1))}register(t,e=!1,s){return this._authServiceApi.signUp(this._toSignUpModel(t)).pipe(n(()=>{e||this.login(c(t.phone),t.password,s).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(n(e=>{this._store.dispatch(new u(e)).pipe(r(1)).subscribe({})}),r(1))}restorePassword(t){let e={password:t.password,phoneConfirmationCode:t.code};return this._authServiceApi.restorePassword(c(t.phone),e).pipe(r(1))}logout(){this._store.dispatch(new _)}_toSignUpModel(t){return{phone:c(t.phone),phoneConfirmationCode:t.code,password:t.password,name:t.name}}};i.\u0275fac=function(e){return new(e||i)(p(A),p(h),p(l))},i.\u0275prov=a({token:i,factory:i.\u0275fac,providedIn:"root"});let o=i;return o})();export{A as a,O as b};
//# sourceMappingURL=chunk-D77MCZOO.js.map
