1import{c as Rt}from"./chunk-THO5MGCT.js";import{b as S,c as o,d as y,e as G,f as Dt}from"./chunk-2MJXGAKW.js";import{b as Pt,c as x}from"./chunk-ALNMNLGQ.js";import{a as St,d as yt,g as Et,h as It,l as Mt,n as Ot}from"./chunk-CJFAJ6X7.js";import{f as vt,h as Ct}from"./chunk-ZGQ2OYA5.js";import{H as gt,g as lt,j as mt,k as ht}from"./chunk-VDWXESJF.js";import{Ea as ut}from"./chunk-JCOTUPE5.js";import{Ab as rt,B as C,Db as nt,Dd as ft,I as X,Ib as at,Ja as D,Nb as ot,P as tt,V as et,_b as ct,bb as P,ec as st,jb as it,l as J,m as j,nd as pt,od as dt,s as Q}from"./chunk-TXT3R3MF.js";import{Ea as f,Ec as u,Fa as s,Fb as K,Ha as $,Hc as T,J as Y,Ja as r,L as M,Lc as b,Mc as N,Md as Z,Nb as w,Nd as V,S as O,T as h,W as d,Yc as H,d as B,fa as z,fc as L,gc as p,kc as v,p as A,q as _,x as c,xa as g,y as I}from"./chunk-PWAHSUDZ.js";import{a as R,b as F}from"./chunk-2BAXZMGZ.js";var E=class{},At=(()=>{class e{constructor(){this.adapter=r(E)}getCtaScripts(t){return this.adapter.getCtaScripts(t)}static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275prov=f({token:e,factory:e.\u0275fac})}}return e})(),Ft=(()=>{class e{constructor(){this.commandService=r(rt),this.opfCtaConnector=r(At),this._readyForScriptEvent=new B,this.readyForScriptEvent$=this._readyForScriptEvent.asObservable(),this.ctaScriptsCommand=this.commandService.create(t=>this.opfCtaConnector.getCtaScripts(t.opfCtaScriptsRequest))}getCtaScripts(t){return this.ctaScriptsCommand.execute({opfCtaScriptsRequest:t})}emitScriptReadyEvent(t){this._readyForScriptEvent.next(t)}listenScriptReadyEvent(){return this.readyForScriptEvent$}static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275prov=f({token:e,factory:e.\u0275fac})}}return e})(),Nt=[Ft,{provide:S,useExisting:Ft}],_t=(()=>{class e{static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275mod=p({type:e})}static{this.\u0275inj=s({providers:[...Nt,At]})}}return e})(),k=(()=>{class e{constructor(){this.globalFunctionsFacade=r(Pt),this.winRef=r(P),this.eventService=r(nt),this.currencyService=r(dt),this.languageService=r(pt),this.activeCartFacade=r(gt),this.opfCtaFacade=r(S),this.currentProductService=r(ut),this.subList=[],this.isOnsiteMessagingInit=!1,this.scriptIdentifiers=[]}fillCtaRequestforCartPage(t,i){return this.isCartPage=!0,I({cart:this.activeCartFacade.takeActive(),additionalData:this.fillAdditionalData()}).pipe(d(1),c(({cart:n,additionalData:a})=>({paymentAccountIds:i,scriptLocations:[t],ctaProductItems:n.entries?.map(m=>({productId:m.product?.code,quantity:m.quantity})),additionalData:a})))}fillCtaRequestforProductPage(t,i){return this.isCartPage=!1,I({product:this.currentProductService.getProduct(),additionalData:this.fillAdditionalData()}).pipe(d(1),c(({product:n,additionalData:a})=>({ctaProductItems:[{productId:n?.code,quantity:1}],paymentAccountIds:i,scriptLocations:[t],additionalData:a})))}fillAdditionalData(){return I({language:this.languageService.getActive(),currency:this.currencyService.getActive()}).pipe(d(1),c(({language:t,currency:i})=>[{key:"locale",value:t},{key:"currency",value:i},{key:"scriptIdentifier",value:this.getNewScriptIdentifier()}]))}initiateEvents(){this.isOnsiteMessagingInit||(this.listenScriptReadyEvent(),this.isCartPage&&this.cartChangedListener(),!this.isCartPage&&this.productChangedListener(),this.isOnsiteMessagingInit=!0)}stopEvents(){this.isOnsiteMessagingInit&&(this.subList.forEach(t=>t.unsubscribe()),this.subList=[],this.globalFunctionsFacade.unregisterGlobalFunctions(x.GLOBAL),this.isOnsiteMessagingInit=!1)}getNewScriptIdentifier(){return this.scriptIdentifiers.push(String(this.scriptIdentifiers.length+1)),String(this.scriptIdentifiers[this.scriptIdentifiers.length-1]).padStart(4,"0")}registerScriptReadyEvent(){this.globalFunctionsFacade.registerGlobalFunctions({paymentSessionId:"",domain:x.GLOBAL})}listenScriptReadyEvent(){let t=this.opfCtaFacade.listenScriptReadyEvent().subscribe({next:i=>{this.isCartPage&&this.dispatchCartEvents([i]),!this.isCartPage&&this.dispatchProductEvents([i])}});this.subList.push(t)}dispatchCartEvents(t){this.activeCartFacade.takeActive().pipe(d(1),c(i=>({total:i.totalPrice?.value})),g(i=>{let a=this.winRef.nativeWindow?.dispatchEvent;a&&a(new CustomEvent(G.OPF_CART_CHANGED,{detail:{cart:i,scriptIdentifiers:t}}
1))})).subscribe()}dispatchProductEvents(t,i=1){this.currentProductService.getProduct().pipe(d(1),c(n=>[{price:{sellingPrice:n?.price?.value},quantity:i}]),g(n=>{let m=this.winRef.nativeWindow?.dispatchEvent;m&&m(new CustomEvent(G.OPF_PRODUCT_AMOUNT_CHANGED,{detail:{productInfo:n,scriptIdentifiers:t}}))})).subscribe()}productChangedListener(){}cartChangedListener(){let t=Y(this.eventService.get(ht),this.eventService.get(lt),this.eventService.get(mt)).subscribe({next:()=>{this.dispatchCartEvents(this.scriptIdentifiers)}});this.subList.push(t)}static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275prov=f({token:e,factory:e.\u0275fac})}}return e})(),U=(()=>{class e{constructor(){this.orderDetailsService=r(Ct),this.orderHistoryService=r(vt)}fillCtaRequestforPagesWithOrder(t){return this.getOrderDetails(t).pipe(c(i=>{if(!i?.paymentInfo?.id)throw new Error("OrderPaymentInfoId missing");return{cartId:i?.paymentInfo?.id,ctaProductItems:this.getProductItems(i),scriptLocations:[t]}}))}getOrderDetails(t){return(t===o.ORDER_CONFIRMATION_PAYMENT_GUIDE?this.orderDetailsService.getOrderDetails():this.orderHistoryService.getOrderDetails()).pipe(M(n=>!!n?.entries))}getProductItems(t){return t.entries.filter(i=>!!i?.product?.code&&!!i?.quantity).map(i=>({productId:i.product?.code,quantity:i.quantity}))}static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275prov=f({token:e,factory:e.\u0275fac})}}return e})(),wt=new $("OpfCtaScriptsNormalizer");function Ht(e,l){if(e&1&&T(0,"div",1),e&2){let t=H();u("innerHTML",t.renderHtml(t.ctaScriptHtml.html),K)}}function jt(e,l){if(e&1&&T(0,"cx-opf-cta-element",2),e&2){let t=l.$implicit;u("ctaScriptHtml",t)}}function Gt(e,l){if(e&1&&(b(0),v(1,jt,1,1,"cx-opf-cta-element",1),N()),e&2){let t=H().ngIf;w(),u("ngForOf",t)}}function xt(e,l){if(e&1&&(b(0),v(1,Gt,2,1,"ng-container",0),N()),e&2){let t=l.ngIf;w(),u("ngIf",t==null?null:t.length)}}var W=(()=>{class e{constructor(){this.opfBaseFacade=r(Ot),this.opfCtaFacade=r(S),this.opfResourceLoaderService=r(Mt),this.cmsService=r(ft),this.opfDynamicCtaService=r(k),this.opfStaticCtaService=r(U),this.subList=[]}loadAndRunScript(t){let i=t?.html;return new Promise(n=>{this.opfResourceLoaderService.loadResources(t.jsUrls,t.cssUrls,void 0,t).then(()=>{i&&t?.htmlContentMode!==It.SEPARATE?(this.opfResourceLoaderService.executeScriptFromHtml(i),n(t)):n(i?t:void 0)}).catch(()=>{n(void 0)})})}
1getCtaHtmlList(){let t=!1;return this.fillCtaScriptRequest().pipe(h(i=>(t=!!i?.scriptLocations?.length&&!!i?.scriptLocations.find(n=>Dt.includes(n)),t&&this.opfDynamicCtaService.registerScriptReadyEvent(),this.fetchCtaScripts(i))),g(i=>{t&&i.length&&this.opfDynamicCtaService.initiateEvents()}),z(()=>{this.opfResourceLoaderService.clearAllResources(),t&&this.opfDynamicCtaService.stopEvents()}))}fetchCtaScripts(t){return this.opfCtaFacade.getCtaScripts(t).pipe(h(i=>{if(!i?.value?.length)return _(()=>"Invalid CTA Scripts Response");let n=i.value.map(a=>a.dynamicScript);return A(n)}),d(1))}fillCtaScriptRequest(){let t;return this.getPaymentAccountIds().pipe(h(i=>(t=i,this.getScriptLocation())),h(i=>this.fillRequestForTargetPage(i,t)))}fillRequestForTargetPage(t,i){if(!t)return _(()=>"Invalid Script Location");let a={[o.ORDER_HISTORY_PAYMENT_GUIDE]:()=>this.opfStaticCtaService.fillCtaRequestforPagesWithOrder(t),[o.ORDER_CONFIRMATION_PAYMENT_GUIDE]:()=>this.opfStaticCtaService.fillCtaRequestforPagesWithOrder(t),[o.CART_MESSAGING]:()=>this.opfDynamicCtaService.fillCtaRequestforCartPage(t,i),[o.PDP_MESSAGING]:()=>this.opfDynamicCtaService.fillCtaRequestforProductPage(t,i)}[t];return a()}getScriptLocation(){let t={[y.ORDER_PAGE]:o.ORDER_HISTORY_PAYMENT_GUIDE,[y.ORDER_CONFIRMATION_PAGE]:o.ORDER_CONFIRMATION_PAYMENT_GUIDE,[y.PDP_PAGE]:o.PDP_MESSAGING,[y.CART_PAGE]:o.CART_MESSAGING};return this.cmsService.getCurrentPage().pipe(d(1),c(i=>i.pageId?t[i.pageId]:void 0))}getPaymentAccountIds(){return this.opfBaseFacade.getActiveConfigurationsState().pipe(M(t=>!t.loading&&!t.error&&!!t.data?.value?.length),c(t=>t.data?.value?.map(i=>i.id)))}static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275prov=f({token:e,factory:e.\u0275fac})}}return e})(),qt=(()=>{class e{constructor(){this.sanitizer=r(et),this.opfCtaScriptsService=r(W),this.windowRef=r(P)}ngAfterViewInit(){this.opfCtaScriptsService.loadAndRunScript(this.ctaScriptHtml)}renderHtml(t){return this.windowRef.isBrowser()?this.sanitizer.bypassSecurityTrustHtml(this.removeScriptTags(t)):t}removeScriptTags(t){let i=new DOMParser().parseFromString(t,"text/html");
1return Array.from(i.getElementsByTagName("script")).forEach(n=>{t=t.replace(n.outerHTML,"")}),t}static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275cmp=L({type:e,selectors:[["cx-opf-cta-element"]],inputs:{ctaScriptHtml:"ctaScriptHtml"},decls:1,vars:1,consts:[[3,"innerHTML",4,"ngIf"],[3,"innerHTML"]],template:function(i,n){i&1&&v(0,Ht,1,1,"div",0),i&2&&u("ngIf",n.ctaScriptHtml&&n.ctaScriptHtml.html)},dependencies:[j],encapsulation:2,changeDetection:0})}}return e})(),Lt=(()=>{class e{static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275mod=p({type:e})}static{this.\u0275inj=s({imports:[C]})}}return e})(),kt=(()=>{class e{constructor(){this.opfCtaScriptService=r(W),this.ctaHtmls$=this.opfCtaScriptService.getCtaHtmlList().pipe(O(()=>A([])))}static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275cmp=L({type:e,selectors:[["cx-opf-cta-scripts"]],decls:2,vars:3,consts:[[4,"ngIf"],[3,"ctaScriptHtml",4,"ngFor","ngForOf"],[3,"ctaScriptHtml"]],template:function(i,n){i&1&&(v(0,xt,2,1,"ng-container",0),Z(1,"async")),i&2&&u("ngIf",V(1,1,n.ctaHtmls$))},dependencies:[j,J,qt,Q],encapsulation:2,changeDetection:0})}}return e})(),Ut=(()=>{class e{static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275mod=p({type:e})}
1static{this.\u0275inj=s({providers:[W,k,U,D({cmsComponents:{OpfCtaScriptsComponent:{component:kt}}})],imports:[C,Lt]})}}return e})(),Tt=(()=>{class e{static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275mod=p({type:e})}static{this.\u0275inj=s({imports:[Ut,Lt]})}}return e})();var Wt=(()=>{class e{constructor(){this.http=r(tt),this.converter=r(at),this.opfEndpointsService=r(Rt),this.opfMetadataStatePersistanceService=r(Et),this.config=r(yt),this.logger=r(it),this.headerWithNoLanguage={accept:"application/json","Content-Type":"application/json"},this.header=F(R({},this.headerWithNoLanguage),{"Accept-Language":this.opfMetadataStatePersistanceService.getActiveLanguage()}),this.headerWithContentLanguage=F(R({},this.headerWithNoLanguage),{"Content-Language":this.opfMetadataStatePersistanceService.getActiveLanguage()})}getCtaScripts(t){let i=new X(this.header).set(St,this.config.opf?.commerceCloudPublicKey||""),n=this.getCtaScriptsEndpoint();return this.http.post(n,t,{headers:i}).pipe(O(a=>{throw st(a,this.logger)}),ct({shouldRetry:ot,maxTries:2}),this.converter.pipeable(wt))}getCtaScriptsEndpoint(){return this.opfEndpointsService.buildUrl("getCtaScripts")}static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275prov=f({token:e,factory:e.\u0275fac})}}return e})(),Bt={backend:{opfApi:{endpoints:{getCtaScripts:"payments/cta-scripts-rendering"}}}},bt=(()=>{class e{static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275mod=p({type:e})}static{this.\u0275inj=s({providers:[D(Bt),{provide:E,useClass:Wt}],imports:[C]})}}return e})();var Le=(()=>{class e{static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275mod=p({type:e})}static{this.\u0275inj=s({imports:[_t,bt,Tt]})}}return e})();export{Le as OpfCtaModule};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.