import{a as c,d as m}from"./chunk-S4U3AIKN.js";import{a as f}from"./chunk-LUVLN4FO.js";import{a as r}from"./chunk-WJ4EUYN3.js";import{X as d,dd as p,gb as g,ia as l,la as n,od as k}from"./chunk-NSJERVUU.js";var j=r.urlBaseNoAuthApi+"/noauth",u=r.newApiChatbotBackApi,h=r.userSession,N=(()=>{let o=class o{constructor(t,e,i,s){this.router=t,this.http=e,this.tokenService=i,this.anotaToastService=s,this.isAppMobile=/anotaaibot/i.test(navigator.userAgent),this.user=g(null),this.logoutLoading=!1,this.tokenService.hasToken()&&this.decodeAndNotify()}setToken(t){this.tokenService.setToken(t),this.decodeAndNotify()}getUser(){return this.user.asReadonly()}setUser(t){this.user.set(t)}verifyToken(t){let e=u+`/auth/session/authentication/forgot-password/verify_token/${t}`;return this.http.get(e)}decodeAndNotify(){let t=this.tokenService.getToken(),e=c(t),i=!!e?.root,s=i&&e?.emailroot?e.emailroot:"N\xE3o identificado";window.localStorage.setItem("isTokenRoot",String(i)),window.localStorage.setItem("user_email",s)}getTokenInfos(){let t=this.tokenService.getToken();return c(t)}logout(){let t=h+"/token/logout/auth";this.logoutLoading||(this.logoutLoading=!0,this.http.put(t,{}).pipe(d(()=>this.logoutLoading=!1)).subscribe({next:()=>this.logoutRedirect(),error:()=>this.logoutRedirect()}))}logoutRedirect(){this.anotaToastService.setShowToast({type:"success",message:"Logout realizado com sucesso"});let t=new CustomEvent("logout");document.dispatchEvent(t),this.tokenService.removeToken(),this.setUser(null),this.isAppMobile?this.router.navigate(["login"]):window.location.href=`${r.adminV1}admin/index.html#/logout?redirectUrl=${window.location.origin}/login`}renewToken(){let t=h+"/token/renew/auth";return this.http.get(t)}isLogged(){return this.tokenService.hasToken()}resetPassword(t,e,i){let s=u+"/auth/session/authentication/update-password";return this.http.post(s,{access_token:t,password:e,password2:i},{observe:"response"})}setRouteToRedirectAfterLogin(t){this.routeToRedirect=t}getRouteToRedirectAfterLogin(){return this.routeToRedirect}getWaiterToken(){let t=h+"/token/auth-to-waiter";return this.http.get(t)}setDeviceToken(t){let e=u+"/auth/user/update-device-token";return this.http.post(e,{deviceToken:t})}};o.\u0275fac=function(e){return new(e||o)(n(k),n(p),n(m),n(f))},o.\u0275prov=l({token:o,factory:o.\u0275fac,providedIn:"root"});let a=o;return a})();export{N as a};
