import{B as f,C as P,Ia as b,R as d,S as g,T as x,Y as O,Za as D,b as v,da as E,na as I,oa as N,pa as w,q as h,r as C,t as y,w as S}from"./chunk-BYJPVSLE.js";import{a as u}from"./chunk-TSRGIXR5.js";var k=["payPalButtonContainer"],B=(()=>{class r{constructor(e){this.zone=e}registerScript(e,t,n){let o=window[t];if(o){this.zone.run(()=>{n(o)});return}let l=document.createElement("script");l.id=this.getElemId(t),l.innerHTML="",l.onload=()=>{this.zone.run(()=>{n(window[t])})},l.src=e,l.async=!0,l.defer=!0,document.getElementsByTagName("head")[0].appendChild(l)}cleanup(e){let t=document.getElementById(this.getElemId(e));t&&t.remove()}getElemId(e){return`ngx-paypal-script-elem-${e}`}}return r.\u0275fac=function(e){return new(e||r)(y(P))},r.\u0275prov=h({token:r,factory:r.\u0275fac}),r})(),M=(()=>{class r{constructor(e){this.scriptService=e,this.paypalWindowName="paypal"}registerPayPalScript(e,t){this.scriptService.registerScript(this.getUrlForConfig(e),this.paypalWindowName,t)}destroyPayPalScript(){this.scriptService.cleanup(this.paypalWindowName)}getUrlForConfig(e){let t=[{name:"client-id",value:e.clientId}];return e.locale&&t.push({name:"locale",value:e.locale}),e.currency&&t.push({name:"currency",value:e.currency}),e.commit&&t.push({name:"commit",value:e.commit}),e.vault&&t.push({name:"vault",value:e.vault}),e.intent&&t.push({name:"intent",value:e.intent}),e.funding&&t.push({name:"components",value:"buttons,funding-eligibility"}),e.extraParams&&t.push(...e.extraParams),`https://www.paypal.com/sdk/js${this.getQueryString(t)}`}getQueryString(e){let t="";for(let n=0;n<e.length;n++){let o=e[n];n===0?t+="?":t+="&",t+=`${o.name}=${o.value}`}return t}}return r.\u0275fac=function(e){return new(e||r)(y(B))},r.\u0275prov=h({token:r,factory:r.\u0275fac}),r})(),$=(()=>{class r{constructor(e,t,n){this.paypalScriptService=e,this.cdr=t,this.ngZone=n,this.registerScript=!0,this.scriptLoaded=new f,this.ngUnsubscribe=new v,this.initializePayPal=!0}set payPalButtonContainer(e){this.payPalButtonContainerElem=e}ngOnChanges(e){this.payPalButtonContainerId||(this.payPalButtonContainerId=this.generateElementId());let t=this.config;e.config.isFirstChange()&&t&&this.registerScript&&this.initPayPalScript(t,n=>{this.payPal=n,this.doPayPalCheck()}),e.config.isFirstChange()||this.reinitialize(t)}ngOnDestroy(){this.paypalScriptService.destroyPayPalScript(),this.ngUnsubscribe.next(),this.ngUnsubscribe.complete()}ngAfterViewInit(){this.doPayPalCheck()}customInit(e){this.payPal=e,this.doPayPalCheck()}reinitialize(e){if(this.config=e,this.payPal=void 0,this.paypalScriptService.destroyPayPalScript(),this.payPalButtonContainerId=this.generateElementId(),this.initializePayPal=!0,this.payPalButtonContainerElem)try{for(;this.payPalButtonContainerElem.nativeElement.firstChild;)this.payPalButtonContainerElem.nativeElement.removeChild(this.payPalButtonContainerElem.nativeElement.firstChild)}catch(t){console.error(t)}this.cdr.detectChanges(),this.config&&(this.payPal?this.doPayPalCheck():this.initPayPalScript(this.config,t=>{this.payPal=t,this.doPayPalCheck()}))}doPayPalCheck(){this.initializePayPal&&this.config&&this.payPal&&this.payPalButtonContainerElem&&this.payPalButtonContainerElem.nativeElement.id&&(this.initializePayPal=!1,this.initPayPal(this.config,this.payPal))}initPayPalScript(e,t){this.paypalScriptService.registerPayPalScript({clientId:e.clientId,locale:e.advanced?.locale,commit:e.advanced&&e.advanced.commit?e.advanced.commit:void 0,currency:e.currency,vault:e.vault,intent:e.intent,funding:e.fundingSource!=null||e.fundingSource!=null,extraParams:e.advanced&&e.advanced.extraQueryParams?e.advanced.extraQueryParams:[]},n=>{this.scriptLoaded.next(n),t(n)})}generateElementId(){return`ngx-captcha-id-${this.generateGuid()}`}initPayPal(e,t){this.ngZone.runOutsideAngular(()=>{let n=(i,a)=>this.ngZone.run(()=>{if(e.createOrderOnClient&&e.createOrderOnServer)throw Error(`Both 'createOrderOnClient' and 'createOrderOnServer' are defined.
                    Please choose one or the other.`);if(!e.createOrderOnClient&&!e.createOrderOnServer)throw Error(`Neither 'createOrderOnClient' or 'createOrderOnServer' are defined.
                    Please define one of these to create order.`);if(e.createOrderOnClient)return a.order.create(e.createOrderOnClient(i));if(e.createOrderOnServer)return e.createOrderOnServer(i);throw Error("Invalid state for 'createOrder'.")}),o=(i,a)=>this.ngZone.run(()=>{if(e.createSubscriptionOnClient)return a.subscription.create(e.createSubscriptionOnClient(i))}),l=(i,a)=>this.ngZone.run(()=>{if(e.onShippingChange)return e.onShippingChange(i,a)}),p=u(u(u({style:e.style,fundingSource:void 0,onApprove:(i,a)=>this.ngZone.run(()=>{if(e.onApprove&&e.onApprove(i,a),e.authorizeOnServer)return e.authorizeOnServer(i,a);let m=e.onClientAuthorization;m&&a.order.capture().then(A=>{this.ngZone.run(()=>{m(A)})})}),onError:i=>{this.ngZone.run(()=>{e.onError&&e.onError(i)})},onCancel:(i,a)=>{this.ngZone.run(()=>{e.onCancel&&e.onCancel(i,a)})},onClick:(i,a)=>{this.ngZone.run(()=>{e.onClick&&e.onClick(i,a)})},onInit:(i,a)=>{this.ngZone.run(()=>{e.onInit&&e.onInit(i,a)})}},(e.createOrderOnClient||e.createOrderOnServer)&&{createOrder:n}),e.createSubscriptionOnClient&&{createSubscription:o}),e.onShippingChange&&{onShippingChange:l}),c;switch(e.fundingSource){case"PAYPAL":c=t.FUNDING.PAYPAL;break;case"CARD":c=t.FUNDING.CARD;break;case"PAYLATER":c=t.FUNDING.PAYLATER;break;case"CREDIT":c=t.FUNDING.CREDIT;break;case"VENMO":c=t.FUNDING.VENMO;break;default:break}c!=null&&(p.fundingSource=c,e.fundingSource!=="PAYPAL"&&delete p.style?.color),t.Buttons(p).render(`#${this.payPalButtonContainerId}`)})}generateGuid(){let e=new Date().getTime(),t=performance&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let o=Math.random()*16;return e>0?(o=(e+o)%16|0,e=Math.floor(e/16)):(o=(t+o)%16|0,t=Math.floor(t/16)),(n=="x"?o:o&7|8).toString(16)})}}return r.\u0275fac=function(e){return new(e||r)(d(M),d(b),d(P))},r.\u0275cmp=g({type:r,selectors:[["ngx-paypal"]],viewQuery:function(e,t){if(e&1&&I(k,5),e&2){let n;N(n=w())&&(t.payPalButtonContainer=n.first)}},inputs:{config:"config",registerScript:"registerScript"},outputs:{scriptLoaded:"scriptLoaded"},standalone:!1,features:[S],decls:2,vars:1,consts:[["payPalButtonContainer",""],[3,"id"]],template:function(e,t){e&1&&E(0,"div",1,0),e&2&&O("id",t.payPalButtonContainerId)},encapsulation:2,changeDetection:0}),r})(),Y=(()=>{class r{}return r.\u0275fac=function(e){return new(e||r)},r.\u0275mod=x({type:r}),r.\u0275inj=C({providers:[B,M],imports:[D]}),r})();export{$ as a,Y as b};
