import{a as he}from"./chunk-SOGEMFNI.js";import{r as de}from"./chunk-BNVEODRX.js";import{b as pe}from"./chunk-AQQKIXHH.js";import{a as R,b as m,c as S,h as ue}from"./chunk-36NROMUK.js";import{f as fe,g as P}from"./chunk-LMJZWCTS.js";import{A as I,B as ce,G as me,Ja as le,M as D,a as Z,b as _,d as E,e as B,ka as h,n as ee,o as $,p as te,r as oe,s as L,t as ie,u as re,v as se,w as ae,x as ne}from"./chunk-E2DT4ALR.js";import{I as d,k as q}from"./chunk-2HRCYW6U.js";import{$c as y,Ca as F,Ea as Q,Tc as W,Uc as v,Va as A,Yc as X,Z as b,ca as a,da as k,ga as i,j as V,k as J,p as T,t as C,ud as x}from"./chunk-MUCMJBU7.js";import{a as p,b as u}from"./chunk-B4AJQJMI.js";var Se=(()=>{class e{constructor(t,o,n,s){this.dialogService=t,this.clienteFacade=o,this.layoutUtilsService=n,this.platformId=s,this.logoutDialog={open:!0,title:"Deseja mesmo sair?",subTitle:"Ao sair, sua conta ser\xE1 deslogada do nosso aplicativo e ter\xE1 que refazer o processo de login. Deseja mesmo sair?",disabled:!1,buttonConfirmText:"N\xE3o, permanecer logado",buttonCancelText:"Sim, deslogar minha conta"},v(this.platformId)&&(this.setupStorageEventListener(),this.setupTabsEventListener())}get isDesktop(){return this.layoutUtilsService.isDesktop()}logout(){this.dialogService.openDialog(this.logoutDialog),this.dialogService.dialogClick.subscribe(t=>{t||(v(this.platformId)&&this.userLoginLogoutChannel?.postMessage("logout"),this.clienteFacade.logout()),this.dialogService.clearDialog()})}setupStorageEventListener(){this.userLoginLogoutChannel=new BroadcastChannel("login-logout"),this.userLoginLogoutChannel.onmessage=t=>{let{data:o}=t;o==="logout"?this.clienteFacade.logout():o==="login"&&this.clienteFacade.init()}}setupTabsEventListener(){this.tabsChannel=new BroadcastChannel("tabs"),this.tabsChannel.postMessage("first-tab"),this.tabsChannel.onmessage=t=>{t.data==="first-tab"&&this.tabsChannel?.postMessage("duplicate-tab"),t.data==="duplicate-tab"&&this.clienteFacade.init()}}static{this.\u0275fac=function(o){return new(o||e)(i(h),i(S),i(d),i(F))}}static{this.\u0275prov=a({token:e,factory:e.\u0275fac})}}return e})();var He=(()=>{class e{static{this.\u0275fac=function(o){return new(o||e)}}static{this.\u0275mod=A({type:e})}static{this.\u0275inj=k({providers:[Se],imports:[P]})}}return e})();var g=E("[Sessao Page] Init"),M=E("[Sessao/API] Load Sessao Success",B()),O=E("[Sessao/API] Load Sessao Failure",B());var U="sessao",ke={data:null,status:I.PENDING,error:""},Fe=ie(ke,L(g,e=>u(p({},e),{status:I.LOADING,error:""})),L(M,(e,{sessaoId:r})=>u(p({},e),{data:{sessaoId:r},status:I.SUCCESS,error:""})),L(O,(e,{error:r})=>u(p({},e),{status:I.ERROR,error:r.error.error})));function ge(e,r){return Fe(e,r)}var G="sessao-id",f=(()=>{class e{constructor(t){this.storage=t,this.sessaoIdCache=null}getSessaoId(){return this.sessaoIdCache?this.sessaoIdCache:(this.sessaoIdCache=this.storage.getItem(G)||"",this.sessaoIdCache)}setSessaoId(t){this.storage.setItem(G,t)}clearSessaoId(){this.sessaoIdCache=null,this.storage.removeItem(G)}static{this.\u0275fac=function(o){return new(o||e)(i(q))}}static{this.\u0275prov=a({token:e,factory:e.\u0275fac,providedIn:"root"})}}return e})();var Ie=(()=>{class e{constructor(t,o,n){this.actions$=t,this.sessaoApiService=o,this.sessaoService=n,this.init$=re(()=>this.actions$.pipe(ae(g,R.logoutSuccess),me({run:()=>this.sessaoApiService.getSessaoId().pipe(C(s=>(this.sessaoService.setSessaoId(s.data.sessao_id),M({sessaoId:s.data.sessao_id})))),onError:(s,c)=>O({error:c})})))}static{this.\u0275fac=function(o){return new(o||e)(i(se),i(le),i(f))}}static{this.\u0275prov=a({token:e,factory:e.\u0275fac})}}return e})();var K=class extends ce{constructor(){super(U),this.getSessaoId=()=>te(this.createFeatureSelector,r=>r.data?.sessaoId)}},H=new K;var je=(()=>{class e{constructor(t,o,n,s,c){this.store=t,this.carrinhoFacade=o,this.carrinhoItensFacade=n,this.clienteTokenService=s,this.sessaoService=c,this.loaded$=this.store.pipe($(H.isLoaded())),this.sessaoId$=this.store.pipe($(H.getSessaoId()))}init(){this.sessaoService.getSessaoId()||this.store.dispatch(g()),!this.clienteTokenService.getToken()&&this.sessaoService.getSessaoId()&&(this.carrinhoFacade.getCarrinho(),this.carrinhoItensFacade.getItensCarrinho())}static{this.\u0275fac=function(o){return new(o||e)(i(ee),i(pe),i(de),i(m),i(f))}}static{this.\u0275prov=a({token:e,factory:e.\u0275fac})}}return e})();var wt=(()=>{class e{static{this.\u0275fac=function(o){return new(o||e)}}static{this.\u0275mod=A({type:e})}static{this.\u0275inj=k({providers:[je],imports:[W,ue,P,oe.forFeature(U,ge),ne.forFeature([Ie])]})}}return e})();var Y=class N{constructor(r,t,o,n,s,c){this.clienteTokenService=r,this.clienteFacade=t,this.lojaTokenService=o,this.sessaoService=n,this.dialogService=s,this.layoutUtilsService=c,this.dialogOpened=!1}intercept(r,t){let o=this.clienteTokenService.getToken(),n=this.sessaoService.getSessaoId(),s=r.headers;s=s.set("sessao-id",n);let c=s.get("Authorization");if(o)return c||(s=s.set("Authorization",`Bearer ${o}`)),t.handle(r.clone({headers:s})).pipe(b({error:j=>{j.status===401&&(j?.error?.message&&this.isLimiteTentativasPagamentos(j.error.message)?this.showDialog(j.error.message):this.clienteFacade.logout())}}));let Te=this.lojaTokenService.getToken();return c||(s=s.set("Authorization",`Bearer ${Te}`)),t.handle(r.clone({headers:s}))}isLimiteTentativasPagamentos(r){return r.includes("Por favor, utilize uma forma de pagamento na entrega ou entre em contato com o nosso atendimento.")}showDialog(r){this.dialogOpened||(this.dialogService.openDialog({open:!0,title:"Voc\xEA excedeu o limite de tentativas para pagamento online",subTitle:r,disabled:!1,buttonConfirmText:"Pagar na entrega",buttonCancelText:"Contatar suporte"},!0),this.dialogOpened=!0,this.dialogService.dialogClick.pipe(_(this)).subscribe(t=>{this.dialogOpened=!1,this.dialogService.clearDialog(),this.clienteFacade.logout(t?"/login":this.layoutUtilsService.isDesktop()?"/institucional/fale-conosco":"/fale-conosco")}))}static{this.\u0275fac=function(t){return new(t||N)(i(m),i(S),i(D),i(f),i(h),i(d))}}static{this.\u0275prov=a({token:N,factory:N.\u0275fac})}};Y=V([Z(),J("design:paramtypes",[m,S,D,f,h,d])],Y);var Qt={provide:y,useClass:Y,multi:!0};var Ee=(()=>{class e{constructor(t,o){this.transferState=t,this.platformId=o,this.isBrowser=v(this.platformId)}intercept(t,o){if(t.method!=="GET")return o.handle(t);let n=t.url;if(this.isBrowser){let s=this.transferState.get(n,null);if(s){let c=new X({body:s,status:200});return this.transferState.remove(n),T(c)}else return o.handle(t)}else return o.handle(t).pipe(b(s=>{this.transferState.set(n,s.body)}))}static{this.\u0275fac=function(o){return new(o||e)(i(Q),i(F))}}static{this.\u0275prov=a({token:e,factory:e.\u0275fac,providedIn:"root"})}}return e})(),so={provide:y,useClass:Ee,multi:!0};function mo(e){return function(r,t){return t.type===R.logoutSuccess.type&&r&&(r={aplicativo:r.aplicativo,parametros:r.parametros,institucional:r.institucional,filial:r.filial,"centro-distribuicao":r["centro-distribuicao"],buckets:r.buckets,"classificacao-mercadologica":r["classificacao-mercadologica"],cashback:u(p({},he),{valorMinimo:r.cashback.valorMinimo,alterarSenhaAtivo:r.cashback.alterarSenhaAtivo}),fidelidade:r.fidelidade,"tipo-entregas":u(p({},r["tipo-entregas"]),{isEntrega:!1})}),e(r,t)}}var ho=(()=>{class e{constructor(t,o){this.clienteTokenService=t,this.router=o}canActivate(t,o){return this.clienteTokenService.getToken()==""?(this.router.navigate(["/login"],{queryParams:{redirectTo:o.url}}),!1):!0}static{this.\u0275fac=function(o){return new(o||e)(i(m),i(x))}}static{this.\u0275prov=a({token:e,factory:e.\u0275fac})}}return e})();var ko=(()=>{class e{constructor(t,o,n){this.clienteTokenService=t,this.parametrosFacade=o,this.router=n}canActivate(){return this.clienteTokenService.getToken()?T(!0):this.parametrosFacade.exigeAutenticacao$.pipe(C(t=>(t&&this.router.navigateByUrl("/login"),!t)))}static{this.\u0275fac=function(o){return new(o||e)(i(m),i(fe),i(x))}}static{this.\u0275prov=a({token:e,factory:e.\u0275fac})}}return e})();export{Se as a,He as b,je as c,wt as d,Qt as e,so as f,mo as g,ho as h,ko as i};