import{c as ce}from"./chunk-TFQ3RBKD.js";import{F as ae,g as ne,o as R}from"./chunk-MXUIPT66.js";import{$d as j,Be as _,Ce as ee,Cf as $,Da as V,Df as H,Ef as P,Fe as h,Fh as oe,Ge as b,Gh as E,K as Y,Lc as Z,Me as w,N as k,Ne as y,Oe as f,Te as C,Ve as M,d as W,da as G,ff as te,gf as l,gg as re,hg as se,id as J,jf as O,la as c,lf as D,ma as L,n as K,o as m,oa as o,oe as T,pf as ie,q as B,s as I,t as A,te as X,ua as U,ud as Q,yc as q}from"./chunk-N6B2OJOY.js";import{a as x,k as z,l as p}from"./chunk-GHL4OFBQ.js";var De=(()=>{let e=class e{};e.\u0275fac=function(r){return new(r||e)},e.\u0275prov=c({token:e,factory:function(r){let s=null;return r?s=new(r||e):s=o(T),s},providedIn:"root"});let i=e;return i})(),ue="asm_enabled",de=(()=>{let e=class e{constructor(t,r,s,a){this.location=t,this.winRef=r,this.launchDialogService=s,this.featureModules=a}load(){this.isEnabled()&&this.addUi()}isEnabled(){return this.isLaunched()&&!this.isUsedBefore()&&this.winRef.localStorage&&this.winRef.localStorage.setItem(ue,"true"),this.isLaunched()||this.isUsedBefore()||this.isEmulateInURL()}isLaunched(){let t=this.location.path().split("?")[1];return!!t&&t.split("&").includes("asm=true")}isEmulateInURL(){return this.location.path().indexOf("assisted-service/emulate?")>0}isUsedBefore(){return this.winRef.localStorage?this.winRef.localStorage.getItem(ue)==="true":!1}addUi(){this.featureModules.resolveFeature("asm").subscribe(()=>this.launchDialogService.launch("ASM"))}};e.\u0275fac=function(r){return new(r||e)(o(Z),o(w),o(ne),o(oe))},e.\u0275prov=c({token:e,factory:e.\u0275fac,providedIn:"root"});let i=e;return i})(),he=(()=>{let e=class e{};e.\u0275fac=function(r){return new(r||e)},e.\u0275mod=U({type:e}),e.\u0275inj=L({providers:[{provide:q,useFactory:le,deps:[de],multi:!0}],imports:[J,ae]});let i=e;return i})();function le(i){return()=>{i.load()}}var v=function(i){return i.START_SESSION="START_SESSION",i.ORDER_HISTORY="ORDER_HISTORY",i.ACTIVE_CART="ACTIVE_CART",i.CUSTOMER_360="CUSTOMER_360",i}(v||{}),ge={asm:{agentSessionTimer:{startingDelayInSeconds:600},customerSearch:{maxResults:20},customerList:{pageSize:5,showAvatar:!0,columns:[{headerLocalizationKey:"asm.customerList.tableHeader.customer",renderer:i=>i?.name??"",actionType:v.START_SESSION},{headerLocalizationKey:"asm.customerList.tableHeader.email",renderer:i=>i?.uid??""},{headerLocalizationKey:"asm.customerList.tableHeader.phone",renderer:i=>i?.defaultAddress?.phone??""},{headerLocalizationKey:"asm.customerList.tableHeader.account",renderer:i=>i?.orgUnit?.name??""},{headerLocalizationKey:"asm.customerList.tableHeader.activeCart",icon:{symbol:R.CART,captionLocalizationKey:"asm.customerList.tableHeader.viewActiveCart"},actionType:v.ACTIVE_CART},{headerLocalizationKey:"asm.customerList.tableHeader.orders",icon:{symbol:R.C360_INVOICE,captionLocalizationKey:"asm.customerList.tableHeader.viewOrders"},actionType:v.ORDER_HISTORY},{headerLocalizationKey:"asm.customerList.tableHeader.customer360",icon:{symbol:R.C360_CIRCLE_USER,captionLocalizationKey:"asm.customerList.tableHeader.viewCustomer360"},actionType:v.CUSTOMER_360}]},userIdHttpHeader:{enable:!0}}},Se=(()=>{let e=class e{constructor(t,r,s){this.config=t,this.userIdService=r,this.userIdConstants=s,this.userIdHeader="sap-commerce-cloud-user-id",this.uniqueUserIdConstants=new Set(Object.values(s))}intercept(t,r){if(!this.config.asm?.userIdHttpHeader?.enable)return r.handle(t);let s=t.context.get(re),a;if(typeof s.sendUserIdAsHeader=="string")a=m(s.sendUserIdAsHeader);else if(s.sendUserIdAsHeader)a=this.userIdService.takeUserId().pipe(I(n=>this.uniqueUserIdConstants.has(n)?void 0:n));else return r.handle(t);return a.pipe(Y(n=>{if(n){let d=t.clone({headers:t.headers.set(this.userIdHeader,n)});return r.handle(d)}else return r.handle(t)}))}};e.\u0275fac=function(r){return new(r||e)(o(T),o(b),o(se))},e.\u0275prov=c({token:e,factory:e.\u0275fac,providedIn:"root"});let i=e;return i})(),u=function(i){return i.CSAgent="CSAgent",i.User="User",i}(u||{}),F=(()=>{let e=class e extends f{constructor(){super(...arguments),this._tokenTarget$=new W(u.User)}getTokenTarget(){return this._tokenTarget$}setTokenTarget(t){this._tokenTarget$.next(t)}getEmulatedUserToken(){return this.emulatedUserToken}setEmulatedUserToken(t){this.emulatedUserToken=t}switchTokenTargetToCSAgent(){this._tokenTarget$.next(u.CSAgent)}switchTokenTargetToUser(){this._tokenTarget$.next(u.User)}clearEmulatedUserToken(){this.emulatedUserToken=void 0}};e.\u0275fac=(()=>{let t;return function(s){return(t||(t=V(e)))(s||e)}})(),e.\u0275prov=c({token:e,factory:e.\u0275fac,providedIn:"root"});let i=e;return i})(),fe=(()=>{let e=class e{constructor(t,r,s,a,n,d){this.authService=t,this.authStorageService=r,this.userIdService=s,this.oAuthLibWrapperService=a,this.store=n,this.userAccountFacade=d}authorizeCustomerSupportAgent(t,r){return p(this,null,function*(){let s,a;this.userAccountFacade.get().subscribe(n=>a=n?.customerId).unsubscribe(),this.authStorageService.getToken().subscribe(n=>s=n).unsubscribe(),this.authStorageService.switchTokenTargetToCSAgent();try{yield this.oAuthLibWrapperService.authorizeWithPasswordFlow(t,r),this.store.dispatch(new h.Logout),a!==void 0&&s!==void 0?(this.userIdService.setUserId(a),this.authStorageService.setEmulatedUserToken(s),this.store.dispatch(new h.Login)):(this.userIdService.setUserId(ee),this.authStorageService.clearEmulatedUserToken())}catch{this.authStorageService.switchTokenTargetToUser()}})}startCustomerEmulationSession(t){this.authStorageService.clearEmulatedUserToken(),this.store.dispatch(new h.Logout),this.userIdService.setUserId(t),this.store.dispatch(new h.Login)}isCustomerSupportAgentLoggedIn(){return A([this.authStorageService.getToken(),this.authStorageService.getTokenTarget()]).pipe(I(([t,r])=>!!(t?.access_token&&r===u.CSAgent)))}isCustomerEmulated(){return this.userIdService.isEmulated()}getCustomerSupportAgentTokenLoading(){return m(!1)}logoutCustomerSupportAgent(){return p(this,null,function*(){let t=this.authStorageService.getEmulatedUserToken(),r;this.userIdService.isEmulated().subscribe(s=>r=s).unsubscribe(),yield this.oAuthLibWrapperService.revokeAndLogout(),this.store.dispatch({type:"[Auth] Logout Customer Support Agent"}),this.authStorageService.setTokenTarget(u.User),r&&t?(this.store.dispatch(new h.Logout),this.authStorageService.setToken(t),this.userIdService.setUserId(_),this.authStorageService.clearEmulatedUserToken(),this.store.dispatch(new h.Login)):this.authService.logout()})}};e.\u0275fac=function(r){return new(r||e)(o(l),o(F),o(b),o(y),o(j),o(ce))},e.\u0275prov=c({token:e,factory:e.\u0275fac,providedIn:"root"});let i=e;return i})(),ve=(()=>{let e=class e extends P{constructor(t,r,s,a,n,d,g,S){super(t,r,a,n,g,d,S),this.authService=t,this.authStorageService=r,this.csAgentAuthService=s,this.oAuthLibWrapperService=a,this.routingService=n,this.globalMessageService=d,this.occEndpointsService=g,this.authRedirectService=S}shouldAddAuthorizationHeader(t){return super.shouldAddAuthorizationHeader(t)||this.isCSAgentTokenRequest(t)}shouldCatchError(t){return super.shouldCatchError(t)||this.isCSAgentTokenRequest(t)}alterRequest(t,r){let s=!!this.getAuthorizationHeader(t),a=this.isCSAgentTokenRequest(t),n=super.alterRequest(t,r);return!s&&a?(n=t.clone({setHeaders:x({},this.createAuthorizationHeader(r))}),D.removeHeader(O,n)):n}isCSAgentTokenRequest(t){return!!D.getInterceptorParam(O,t.headers)}handleExpiredRefreshToken(){this.csAgentAuthService.isCustomerSupportAgentLoggedIn().pipe(k(1)).subscribe(t=>{t?(this.authService.setLogoutProgress(!0),this.csAgentAuthService.logoutCustomerSupportAgent(),this.globalMessageService.add({key:"asm.csagentTokenExpired"},$.MSG_TYPE_ERROR)):super.handleExpiredRefreshToken()})}};e.\u0275fac=function(r){return new(r||e)(o(l),o(f),o(fe),o(y),o(C),o(H),o(ie),o(M))},e.\u0275prov=c({token:e,factory:e.\u0275fac,providedIn:"root"});let i=e;return i})(),pe=(()=>{let e=class e extends l{constructor(t,r,s,a,n,d,g,S){super(t,r,s,a,n,g,S),this.store=t,this.userIdService=r,this.oAuthLibWrapperService=s,this.authStorageService=a,this.authRedirectService=n,this.globalMessageService=d,this.routingService=g,this.authMultisiteIsolationService=S}canUserLogin(){let t,r;return this.authStorageService.getToken().subscribe(s=>r=s).unsubscribe(),this.authStorageService.getTokenTarget().subscribe(s=>t=s).unsubscribe(),!(r?.access_token&&t===u.CSAgent)}warnAboutLoggedCSAgent(){this.globalMessageService.add({key:"asm.auth.agentLoggedInError"},$.MSG_TYPE_ERROR)}loginWithCredentials(t,r){return p(this,null,function*(){this.canUserLogin()?yield z(e.prototype,this,"loginWithCredentials").call(this,t,r):this.warnAboutLoggedCSAgent()})}loginWithRedirect(){return this.canUserLogin()?(super.loginWithRedirect(),!0):(this.warnAboutLoggedCSAgent(),!1)}coreLogout(){return B(this.userIdService.isEmulated().pipe(k(1),G(t=>t?(this.authStorageService.clearEmulatedUserToken(),this.userIdService.clearUserId(),this.store.dispatch(new h.Logout),m(!0)):K(super.coreLogout()))))}isUserLoggedIn(){return A([this.authStorageService.getToken(),this.userIdService.isEmulated(),this.authStorageService.getTokenTarget()]).pipe(I(([t,r,s])=>!!t?.access_token&&(s===u.User||s===u.CSAgent&&r)))}};e.\u0275fac=function(r){return new(r||e)(o(j),o(b),o(y),o(F),o(M),o(H),o(C),o(te))},e.\u0275prov=c({token:e,factory:e.\u0275fac,providedIn:"root"});let i=e;return i})(),$e=(()=>{let e=class e{};e.\u0275fac=function(r){return new(r||e)},e.\u0275mod=U({type:e}),e.\u0275inj=L({providers:[X(ge),{provide:f,useExisting:F},{provide:l,useExisting:pe},{provide:P,useExisting:ve},{provide:Q,useExisting:Se,multi:!0}],imports:[he]});let i=e;return i})(),N="asm",He=(()=>{let e=class e{};e.\u0275fac=function(r){return new(r||e)},e.\u0275prov=c({token:e,factory:()=>E({facade:e,feature:N,methods:["bindCart"]}),providedIn:"root"});let i=e;return i})(),Pe=(()=>{let e=class e{};e.\u0275fac=function(r){return new(r||e)},e.\u0275prov=c({token:e,factory:()=>E({facade:e,feature:N,methods:["createCustomer"]}),providedIn:"root"});let i=e;return i})(),Fe=(()=>{let e=class e{};e.\u0275fac=function(r){return new(r||e)},e.\u0275prov=c({token:e,factory:()=>E({facade:e,feature:N,methods:["getCustomerLists","getCustomerListsState","customerListCustomersSearch","getCustomerListCustomersSearchResults","getCustomerListCustomersSearchResultsLoading","customerListCustomersSearchReset","getCustomerListCustomersSearchResultsError"]}),providedIn:"root"});let i=e;return i})(),Ne=(()=>{let e=class e{constructor(t,r,s){this.routingService=t,this.winRef=r,this.asmEnablerService=s,this.searchParams=new URLSearchParams(this.winRef?.location?.search)}isEmulateInURL(){return this.asmEnablerService?.isEmulateInURL()||!1}getSearchParameter(t){return this.searchParams.get(t)??void 0}handleNavigation(t=this.getParamsInUrl()){t.cartType==="active"?this.routingService.go({cxRoute:"cart"}):t.cartType==="saved"&&t.cartId?this.routingService.go("my-account/saved-cart/"+t.cartId):t.orderId?this.routingService.go({cxRoute:"orderDetails",params:{code:t.orderId}}):t.ticketId&&this.routingService.go({cxRoute:"supportTicketDetails",params:{ticketCode:t.ticketId}})}getParamsInUrl(){let t={customerId:this.getSearchParameter("customerId"),orderId:this.getSearchParameter("orderId"),ticketId:this.getSearchParameter("ticketId"),cartId:this.getSearchParameter("cartId"),cartType:this.getSearchParameter("cartType")};return Object.fromEntries(Object.entries(t).filter(([r,s])=>!!s))}};e.\u0275fac=function(r){return new(r||e)(o(C),o(w),o(de))},e.\u0275prov=c({token:e,factory:e.\u0275fac,providedIn:"root"});let i=e;return i})();export{De as a,ue as b,de as c,v as d,F as e,fe as f,pe as g,$e as h,N as i,He as j,Pe as k,Fe as l,Ne as m};