import{a as z}from"./chunk-YLJ24GGY.js";import{b as W}from"./chunk-3VU4UGNC.js";import{Ga as x,S as be,hc as T,jc as G,pa as Ee}from"./chunk-W2ZDDUN5.js";import{$g as Ce,Cf as le,D as q,Dg as he,Fa as K,Fd as X,Hg as pe,J as D,Ke as ne,Kf as fe,La as J,Le as se,N as g,Of as y,Pa as Y,Rg as ve,Se as U,Te as oe,Tf as S,Uf as ge,Ye as N,a as I,b as $,ce as ee,dd as Z,de as te,e as M,ed as V,ha as C,he as ie,hh as Se,i as F,ib as A,ie as re,la as l,n as p,nf as ce,o as u,p as B,pb as _,pd as Q,ph as me,qf as ae,ra as f,rf as de,s as H,sa as j,ta as k,ua as o,ue as L,xg as O,yf as ue}from"./chunk-5LB5MWMX.js";import{a as h,b as E}from"./chunk-QWWW7GFA.js";var je=(()=>{class r{constructor(){}convert(e,t){if(e){let i=e.id?.concat(".isConsentGranted"),n=!1;i&&(e.currentConsent?.consentGivenDate&&(n=!0),t=this.convertToCdcPreference(i,n))}return t}convertToCdcPreference(e,t){let i={},n=i;ae(n);let s=e.split("."),c=s.length;for(let d=0;d<c-1;d++){let a=s[d];n[a]||(n[a]={}),n=n[a]}return n[s[c-1]]=t,i}static{this.\u0275fac=function(t){return new(t||r)}}static{this.\u0275prov=f({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})(),ye="cdc-consents-list",P=(()=>{class r{constructor(e){this.statePersistenceService=e,this.subscription=new I}persistCdcConsentsToStorage(e){let t=[],i=e.siteConsentDetails;for(let n in i)if(Object.hasOwn(i,n)&&i[n]?.isActive===!0){let s={};s.id=n,s.required=i[n]?.isMandatory,t.push(s)}this.subscription.add(this.statePersistenceService.syncWithStorage({key:ye,state$:p(t)}))}readCdcConsentsFromStorage(){return this.statePersistenceService.readStateFromStorage({key:ye})}checkIfConsentExists(e){let t=this.readCdcConsentsFromStorage(),i=!1;return t.forEach(n=>{n.id===e&&(i=!0)}),i}ngOnDestroy(){this.subscription.unsubscribe()}static{this.\u0275fac=function(t){return new(t||r)(o(de))}}static{this.\u0275prov=f({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})(),ke=(()=>{class r extends x{constructor(e){super(),this.store=e}getRequiredConsents(e){let t=[],i=this.getCdcConsentIDs(!0);return t.push(...super.getRequiredConsents(e)),t.push(...i),t}getCdcConsentIDs(e=!1){let t=[];return(this.store.readCdcConsentsFromStorage()||[]).forEach(n=>{e===!0?n.required===!0&&t.push(n.id):t.push(n.id)}),t}isConsentMandatory(e){return this.getCdcConsentIDs(!0).includes(e)}static{this.\u0275fac=function(t){return new(t||r)(o(P))}}static{this.\u0275prov=f({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})(),Re=new k("CdcUserPreferenceSerializer"),we=new k("CdcPreferenceSerializer"),Ae=(()=>{class r{static{this.\u0275fac=function(t){return new(t||r)}}static{this.\u0275prov=f({token:r,factory:function(t){let i=null;return t?i=new(t||r):i=o(te),i},providedIn:"root"})}}return r})();be.CDC_RECONSENT="CDC_RECONSENT";var Le=(()=>{class r{convert(e,t){return e.reduce((i,n)=>{if(!n.id)return i;let s=`${n.id}.isConsentGranted`,c=n.isConsentGranted===!0,d=this.convertToCdcPreference(s,c);return ee(i,d)},{})}convertToCdcPreference(e,t){return e.split(".").reduceRight((i,n)=>({[n]:i}),t)}static{this.\u0275fac=function(t){return new(t||r)}}static{this.\u0275prov=f({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})(),dt=(()=>{class r extends U{static{this.type="CdcLoadUserTokenFailEvent"}}return r})(),Ue=(()=>{class r extends U{static{this.type="CdcReConsentEvent"}}return r})(),Pe="cdc",Ie="cdcCore",Ne=(()=>{class r{static{this.\u0275fac=function(t){return new(t||r)}}static{this.\u0275prov=f({token:r,factory:()=>me({facade:r,feature:Ie,methods:["loginWithCustomCdcFlow","loginWithToken"],async:!0}),providedIn:"root"})}}return r})(),Oe=3600,m="accounts.setAccountInfo",Me=(()=>{class r{constructor(e,t,i,n,s,c,d,a,v,b,w,Fe,De){this.cdcConfig=e,this.baseSiteService=t,this.languageService=i,this.scriptLoader=n,this.winRef=s,this.cdcAuth=c,this.auth=d,this.zone=a,this.userProfileFacade=v,this.platform=b,this.globalMessageService=w,this.eventService=Fe,this.consentStore=De,this.loaded$=new M(1),this.errorLoading$=new M(1),this.subscription=new I}initialize(){this.loadCdcJavascript()}didLoad(){return this.loaded$.asObservable()}didScriptFailToLoad(){return this.errorLoading$.asObservable()}loadCdcJavascript(){V(this.platform)&&this.subscription.add(H([this.baseSiteService.getActive(),this.languageService.getActive()]).pipe(g(1)).subscribe(([e,t])=>{let i=this.getJavascriptUrlForCurrentSite(e);if(i){let n=`${i}&lang=${t}`;this.scriptLoader.embedScript({src:n,params:void 0,attributes:{type:"text/javascript"},callback:()=>{this.registerEventListeners(e),this.getSiteConsentDetails(!0).subscribe(),this.loaded$.next(!0),this.errorLoading$.next(!1)},errorCallback:()=>{this.errorLoading$.next(!0),this.loaded$.next(!1)}}),this.winRef?.nativeWindow!==void 0&&(this.winRef.nativeWindow.__gigyaConf={include:"id_token, missing-required-fields, preferences"})}}))}getJavascriptUrlForCurrentSite(e){let t=(this.cdcConfig.cdc??[]).filter(i=>i.baseSite===e);return t&&t.length>0?t[0].javascriptUrl:""}registerEventListeners(e){this.addCdcEventHandlers(e)}addCdcEventHandlers(e){this.gigyaSDK=this.winRef.nativeWindow?.gigya,this.gigyaSDK?.accounts?.addEventHandlers({onLogin:(...t)=>this.zone.run(()=>this.onLoginEventHandler(e,...t))})}onLoginEventHandler(e,t){t&&!t?.context?.skipOccAuth&&this.cdcAuth.loginWithCustomCdcFlow(t.UID,t.UIDSignature,t.signatureTimestamp,t.id_token!==void 0?t.id_token:"",e)}registerUserWithoutScreenSet(e){return!e.uid||!e.password?u(()=>null):this.invokeAPI("accounts.initRegistration",{}).pipe(C(t=>this.onInitRegistrationHandler(e,t)))}onInitRegistrationHandler(e,t){if(!t?.regToken||!e?.uid||!e?.password)return u(()=>null);{let i=this.winRef.nativeWindow?.location?.href||"";return this.invokeAPI("accounts.register",{email:e.uid,password:e.password,profile:{firstName:e.firstName,lastName:e.lastName},preferences:e.preferences,regSource:i,regToken:t.regToken,finalizeRegistration:!0}).pipe(g(1),l({error:n=>this.handleRegisterError(n)}))}}loginUserWithoutScreenSet(e,t,i){let s=!1,c=this.getCurrentBaseSiteChannel();return c&&c==="B2C"&&(s=!0),this.getSessionExpirationValue().pipe(C(d=>this.invokeAPI("accounts.login",E(h({loginID:e,password:t,ignoreInterruptions:s},i&&{context:i}),{sessionExpiry:d})).pipe(g(1),l({error:a=>{a.errorCode!==206001?this.handleLoginError(a):this.raiseCdcReconsentEvent(e,t,a.missingRequiredFields,a.errorMessage,a.regToken,a.preferences)}}))))}registerOrganisationWithoutScreenSet(e){if(!e?.companyName||!e?.email||!e?.firstName||!e?.lastName)return u("Organization details not provided");{let t=this.winRef.nativeWindow?.location?.href||"",i=e.message,n=null,s=null;return i&&({department:n,position:s}=this.parseMessage(i)),this.invokeAPI("accounts.b2b.registerOrganization",{organization:{name:e.companyName,street_address:e.addressLine1+" "+e.addressLine2,city:e.town,state:e.region,zip_code:e.postalCode,country:e.country},requester:E(h({firstName:e.firstName,lastName:e.lastName,email:e.email},e.phoneNumber&&e.phoneNumber.length>0&&{phone:e.phoneNumber}),{department:n,jobFunction:s}),regSource:t}).pipe(g(1),l({error:c=>this.handleRegisterError(c)}))}}getOrganizationContext(){return this.invokeAPI("accounts.b2b.getOrganizationContext",{})}openDelegatedAdminLogin(e){return this.zone.run(()=>this.gigyaSDK?.accounts?.b2b?.openDelegatedAdminLogin({orgId:e}))}handleRegisterError(e){if(e&&e.status==="FAIL"){let t=e.validationErrors&&e.validationErrors.length>0&&e.validationErrors[e.validationErrors.length-1].message||"Error";this.globalMessageService.add(t,S.MSG_TYPE_ERROR)}}handleLoginError(e){e&&e.status==="FAIL"&&this.globalMessageService.add({key:"httpHandlers.badRequestPleaseLoginAgain",params:{errorMessage:e.errorMessage}},S.MSG_TYPE_ERROR)}getSessionExpirationValue(){if(this.cdcConfig?.cdc!==void 0){let e=this.cdcConfig.cdc.filter(t=>t.baseSite===this.getCurrentBaseSite());if(e&&e.length>0)return p(e[0].sessionExpiration)}return p(Oe)}parseMessage(e){let t=e.replace(`
`,"").split(";"),i="",n="";for(let s of t)s.trim().toLowerCase().search("department")===0?i=s.split(":")[1].trim():s.trim().toLowerCase().search("position")===0&&(n=s.split(":")[1].trim());return{department:i,position:n}}getCurrentBaseSite(){let e="";return this.baseSiteService.getActive().pipe(g(1)).subscribe(t=>e=t),e}getCurrentBaseSiteChannel(){let e="",t=this.getCurrentBaseSite();return this.baseSiteService.get(t).pipe(g(1)).subscribe(i=>e=i?.channel??""),e}resetPasswordWithoutScreenSet(e){return!e||e?.length===0?u(()=>"No email provided"):this.invokeAPI("accounts.resetPassword",{loginID:e}).pipe(g(1),l({error:t=>this.handleResetPassResponse(t)}))}handleResetPassResponse(e){if(e&&e.status==="OK")this.globalMessageService.add({key:"forgottenPassword.passwordResetEmailSent"},S.MSG_TYPE_CONFIRMATION);else{let t=e?.errorMessage||{key:"httpHandlers.unknownError"};this.globalMessageService.add(t,S.MSG_TYPE_ERROR)}}updateProfileWithoutScreenSet(e){if(!e?.firstName||e?.firstName?.length===0||!e?.lastName||e?.lastName?.length===0)return u(()=>"User details not provided");{let t={profile:{firstName:e.firstName,lastName:e.lastName}};return this.invokeAPI(m,h({},t)).pipe(g(1),l(()=>this.userProfileFacade.update(e).subscribe({error:i=>p(i)})))}}updateUserPasswordWithoutScreenSet(e,t){return!e||e?.length===0||!t||t?.length===0?u(()=>"No passwords provided"):this.invokeAPI(m,{password:e,newPassword:t}).pipe(l({error:i=>p(i)}))}onProfileUpdateEventHandler(e,t=!1){if(e){let i={};i.firstName=e.profile.firstName,i.lastName=e.profile.lastName,i.uid=e.profile.email,this.getLoggedInUserEmail().subscribe(n=>{let s=n?.uid;this.userProfileFacade.update(i).subscribe(()=>{(s!==i.uid||t)&&this.logoutUser(),this.handleProfileUpdateResponse(e)})})}else this.handleProfileUpdateResponse(e)}handleProfileUpdateResponse(e){e?.response?.errorCode===0?this.globalMessageService.add({key:"cdcProfile.profileUpdateSuccess"},S.MSG_TYPE_CONFIRMATION):this.globalMessageService.add({key:"cdcProfile.profileUpdateFailure"},S.MSG_TYPE_ERROR)}updateUserEmailWithoutScreenSet(e,t){return!e||e?.length===0||!t||t?.length===0?u(()=>"Email or password not provided"):this.getLoggedInUserEmail().pipe(C(i=>{let n=i?.uid;return!n||n?.length===0?u(()=>"Email or password not provided"):this.loginUserWithoutScreenSet(n,e,{skipOccAuth:!0}).pipe(C(()=>this.invokeAPI(m,{profile:{email:t}}).pipe(g(1),l({next:()=>this.userProfileFacade.update({uid:t}).pipe(g(1),l({error:s=>p(s),complete:()=>{this.logoutUser()}}))}))))}))}getLoggedInUserEmail(){return this.userProfileFacade.get().pipe(q(e=>!!e),g(1))}updateAddressWithoutScreenSet(e,t,i,n){if(!e||e?.length===0)return u(()=>"No address provided");{let s=h(h(h({address:e},i&&{city:i}),n&&{country:n}),t&&{zip:t});return this.invokeAPI(m,{profile:s})}}getSdkFunctionFromName(e){let t=e.split("."),i=this.gigyaSDK;return t.forEach(n=>{i&&i.hasOwnProperty(n)&&(i=i[n])}),i}invokeAPI(e,t){return new $(i=>{let n=this.getSdkFunctionFromName(e);if(typeof n!="function"){i.error("CDC API name is incorrect");return}n(E(h({},t),{callback:s=>{this.zone.run(()=>{s?.status==="OK"?(i.next(s),i.complete()):i.error(s)})}}))})}getSiteConsentDetails(e=!1){let t=this.getCurrentBaseSite(),i=this.getJavascriptUrlForCurrentSite(t),s=new URLSearchParams(i.substring(i.indexOf("?"))).get("apikey");return this.invokeAPI("accounts.getSiteConsentDetails",{apiKey:s}).pipe(l({next:c=>{e&&this.consentStore.persistCdcConsentsToStorage(c)}}))}setUserConsentPreferences(e,t,i,n){let s=this.winRef.nativeWindow?.location?.href||"";return this.invokeAPI(m,{uid:e,lang:t,preferences:i,regSource:s,regToken:n}).pipe(l({error:c=>{u(c)}}))}raiseCdcReconsentEvent(e,t,i,n,s,c){let d=[];i.forEach(v=>{let w=v.replace("preferences.","").replace(".isConsentGranted","");d.push(w)});let a=new Ue;a.user=e,a.password=t,a.consentIds=d,a.errorMessage=n,a.regToken=s,a.preferences=c,this.eventService.dispatch(a)}logoutUser(){this.auth.logout(),this.invokeAPI("accounts.logout",{})}ngOnDestroy(){this.subscription&&this.subscription.unsubscribe()}static{this.\u0275fac=function(t){return new(t||r)(o(Ae),o(ne),o(O),o(ce),o(L),o(Ne),o(y),o(J),o(W),o(Y),o(ge),o(oe),o(P))}}static{this.\u0275prov=f({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})(),xe=(()=>{class r{constructor(e,t,i,n,s){this.languageService=e,this.userProfileFacade=t,this.cdcJsService=i,this.converter=n,this.cdcConsentsStorage=s}updateCdcConsent(e,t,i,n){let s,c={};for(let v of t){s={},s.id=v,s.currentConsent={},e?s.currentConsent.consentGivenDate=new Date:s.currentConsent.consentWithdrawnDate=new Date;let b=this.converter.convert(s,Re);c=Object.assign(c,b)}let d="";i===void 0?d=this.getUserID()??"":i!==void 0&&(d=i);let a=this.getActiveLanguage();return this.cdcJsService.setUserConsentPreferences(d,a,c,n).pipe(l({error:v=>{u(v)}}))}updateCdcUserPreferences(e,t,i){let n=this.converter.convert(e,we),s="";t===void 0?s=this.getUserID()??"":t!==void 0&&(s=t);let c=this.getActiveLanguage();return this.cdcJsService.setUserConsentPreferences(s,c,n,i).pipe(l({error:d=>{u(d)}}))}getUserID(){let e;return this.userProfileFacade.get().subscribe(t=>{e=t?.uid}),e}getActiveLanguage(){let e="";return this.languageService.getActive().subscribe(t=>e=t).unsubscribe(),e}static{this.\u0275fac=function(t){return new(t||r)(o(O),o(W),o(Me),o(N),o(P))}}static{this.\u0275prov=f({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})(),Te=(()=>{class r extends he{constructor(e,t,i,n,s){super(e,t,i),this.http=e,this.occEndpoints=t,this.converter=i,this.cdcUserConsentService=n,this.cdcConsentsStorage=s}loadConsents(e){return super.loadConsents(e)}giveConsent(e,t,i){return this.cdcConsentsStorage.checkIfConsentExists(t)?this.cdcUserConsentService.updateCdcUserPreferences([{id:t,isConsentGranted:!0}]).pipe(D(n=>u(n)),C(n=>n?.errorCode===0?super.giveConsent(e,t,i):F)):super.giveConsent(e,t,i)}withdrawConsent(e,t,i){return this.cdcConsentsStorage.checkIfConsentExists(i??"")?this.cdcUserConsentService.updateCdcUserPreferences([{id:i??"",isConsentGranted:!1}]).pipe(D(n=>u(n)),C(n=>n?.errorCode===0?super.withdrawConsent(e,t):F)):super.withdrawConsent(e,t)}static{this.\u0275fac=function(t){return new(t||r)(o(Q),o(se),o(N),o(xe),o(P))}}static{this.\u0275prov=f({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})(),Ge=(()=>{class r{static{this.\u0275fac=function(t){return new(t||r)}}static{this.\u0275mod=A({type:r})}static{this.\u0275inj=j({providers:[{provide:pe,useClass:Te},{provide:x,useClass:ke},{provide:Re,useExisting:je,multi:!0},{provide:we,useExisting:Le,multi:!0}],imports:[Z,Se]})}}return r})(),We={cdcLogin:{paths:["/cdc/login"],protected:!1,authFlow:!0},cdcCheckoutLogin:{paths:["/cdc/checkout-login"],protected:!1,authFlow:!0},cdcOrgRegistration:{paths:["/cdc/register-org"],protected:!1,authFlow:!0},login:{paths:["login"],protected:!1,authFlow:!0},loginForm:{paths:[],protected:!1,authFlow:!0}},ze={routing:{routes:We}},$e=(()=>{class r extends G{constructor(e,t,i,n,s,c){super(e,t,i,n,s),this.auth=e,this.cms=t,this.semanticPathService=i,this.protectedRoutes=n,this.router=s,this.winRef=c}logoutFromCdc(){this.winRef.nativeWindow?.gigya?.accounts?.logout()}logout(){return Promise.all([super.logout(),this.logoutFromCdc()])}static{this.\u0275fac=function(t){return new(t||r)(o(y),o(ve),o(fe),o(Ce),o(X),o(L))}}static{this.\u0275prov=f({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})(),Be=(()=>{class r extends T{constructor(e,t,i){super(e,t,i),this.authService=e,this.authConfigService=t,this.cmsPageGuard=i}shouldRenderCMSPage(){return p(!0)}static{this.\u0275fac=function(t){return new(t||r)(o(y),o(ue),o(Ee))}}static{this.\u0275prov=f({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})(),He=(()=>{class r extends z{getPath(){return this.semanticPathService.get("login")}static{this.\u0275fac=(()=>{let e;return function(i){return(e||(e=K(r)))(i||r)}})()}static{this.\u0275prov=f({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})();function qe(r,R){return()=>B(R.getStable("context","cdc").pipe(l(()=>{r.initialize()})))}function Ke(){return{featureModules:{[Pe]:{cmsComponents:["GigyaRaasComponent"]},[Ie]:Pe}}}var ut=(()=>{class r{static{this.\u0275fac=function(t){return new(t||r)}}static{this.\u0275mod=A({type:r})}static{this.\u0275inj=j({providers:[re(Ke),{provide:G,useExisting:$e},{provide:T,useExisting:Be},{provide:z,useExisting:He},{provide:_,useFactory:qe,deps:[Me,le],multi:!0},ie(ze)],imports:[Ge]})}}return r})();export{P as a,Ae as b,dt as c,Pe as d,Ne as e,Me as f,ut as g};