var _____WB$wombat$assign$function_____=function(name){return (globalThis._wb_wombat && globalThis._wb_wombat.local_init && globalThis._wb_wombat.local_init(name))||globalThis[name];};if(!globalThis.__WB_pmw){globalThis.__WB_pmw=function(obj){this.__WB_source=obj;return this;}}var window = _____WB$wombat$assign$function_____("window");
var self = _____WB$wombat$assign$function_____("self");
var document = _____WB$wombat$assign$function_____("document");
var location = _____WB$wombat$assign$function_____("location");
var top = _____WB$wombat$assign$function_____("top");
var parent = _____WB$wombat$assign$function_____("parent");
var frames = _____WB$wombat$assign$function_____("frames");
var opener = _____WB$wombat$assign$function_____("opener");
import{bH as Ne,e4 as xe,e5 as Be,a0 as We,e6 as De,e as Ve,dD as Ge,b2 as Ye,e7 as He,bo as Xe,a1 as qe,i as Je,dW as Ue,e8 as ue,e9 as $e,ea as ze,a2 as Qe,b0 as Ze,eb as je,ec as Ke,ed as pe,ee as Fe,ef as u,b7 as et,bL as tt,al as at,eg as st,eh as de,bQ as nt,aX as n,ei as v,ej as me,ek as ve,el as rt,em as ot,en as ye,eo as lt,ep as ct,bZ as it,a7 as ut,a as x,eq as pt,er as dt,G as mt}from"./app.ZXowmuNl.js";import{P as fe,u as vt,c as yt}from"./useApproveHandler.CfJRqfNQ.js";const ft="PAYPAL_EXPRESS",Et={ORDER:"order",BILLING_AGREEMENT:"TOKENIZE"},ge="disable-view-transitions-for-paypal-pci",gt="54px",Ee="PAYPAL_EXPRESS",Pt=()=>{const r=document.createElement("style");r.setAttribute("id",ge),r.textContent=`
    * {
      view-transition-name: none !important;
    }
  `,document.head.appendChild(r)},At=()=>{const r=document.getElementById(ge);r&&r.remove()};class St extends Error{name="PayPalPaymentFlowError"}class Tt extends Error{name="PaypalMissingConfigurationError"}function It({buttonLabel:r="paypal",progressToNextPage:B=!1,isPayWithPayPalFlow:t=!1,fundingSource:a="paypal",isDisabled:Pe=!1}){const W=Ne(),D=xe().geolocation.country.code,V=Be(),{email:G,billingAddressOption:Y}=We(),H=De(),{progress:X,negotiate:P}=Ve(),{currentPage:q}=Ge(),{markAsLoaded:T}=Ye(),J=He("payPal"),U=Xe(),$=qe()?.value,z=Je(),I=$?.find(e=>e.type==="wallet"&&e.name===Ee)?.clientToken,y=Ue(Ee)?.paymentIntent===Et.BILLING_AGREEMENT,M=a==="paypal"?ue.PayPalV6:ue.Venmo,Q=$e(),Ae=ze(M),A=Qe(),S=Ze(),Z=je(M),j=Ke(M),d=pe(null),{isScrimOpen:f,closePopupWindowsAndScrim:Se}=Fe({endpoint:d}),m=pe(!1),K=u(Pe),o=u(Ae),F=u($),{activeWalletSessionSignal:R,isInPayPalContextSignal:O,inMemoryPayPalParts:{isLoadingPaymentSheet:i,accountStatus:h,isApproving:C},inMemoryVenmoParts:{buttonStatus:_},telemetry:{lastClickedWallet:ee}}=et(),L=tt({isPayWithPayPalButton:t}),w=at(null),te=st(),E=t?de.PaymentMethod:de.Express,he=a==="venmo"?z("brand.venmo","Venmo"):z("brand.paypal","PayPal");nt({active:C.value});const p=n(e=>{o.current(v.Failure),A.notify(e),h.value={status:"error"}},[o,A,h]),g=n((e,l)=>{l==="venmo"?_.value={status:e}:L.value={status:e}},[_,L]),ae=n(()=>me()||ve()||rt(),[]),Ce=n(async e=>{const l=ot(w.current);if(a==="venmo"&&(ae()||y)){g("not_eligible",a),T();return}d.value=e;const c=await e.call.configure({clientToken:I,locale:V,fundingSource:a,isBillingAgreement:y,buttonLabel:r,isPayWithPayPal:t,browserSupportsPopupFlow:!me()&&!ve(),style:{borderRadius:l}});T(),c?.status===ye.Success?g("rendered",a):(c.status===ye.Error&&A.notify(new fe(c.message)),o.current(v.Failure),h.value={status:"error"},g("error",a))},[a,ae,d,I,V,y,r,t,T,g,o,h,A]),se=n(()=>{Pt(),m.value=!0},[m]),b=n(()=>{m.value&&(d.value?.call.cleanup(),At(),m.value=!1)},[d.value,m]),s=n(e=>{f.value=e,R.value=e,e||b()},[f,R,b]),be=vt({fundingSource:a,isPayWithPayPalFlow:t,onSuccess:async()=>{C.value=!0,o.current(v.Success,E),S.counter({name:"paypal_approved",value:1,attributes:{payWithPayPal:t,fundingSource:a,PCIv4:!0}}),s(!1)},onError:e=>{p(e),s(!1)}}),N=u(be),ke=n(async()=>{if(te(w),K.current){s(!1),d.value?.call.closePopupWindows();return}if(i.value=!0,o.current(v.Clicked,E),f.value=!0,!t||q?.id==="review"){o.current(v.Initialized,E),s(!0);return}try{const l=await new Promise(c=>{P({runListenersOnError:!0,progression:!1,include:!lt(F.current)&&Y.value==="custom"?["billingAddress"]:[],onComplete:we=>{c(we)}})});if(l.status==="success")o.current(v.Initialized,E),s(!0);else if(s(!1),d.value.call.closePopupWindows(),i.value=!1,l.status!=="error")throw new fe(`unhandled negotiation result when validating guest checkout for PayPal: ${l.status}`)}catch(l){p(l)}},[te,K,i,o,E,f,t,q?.id,s,d.value,P,F,Y.value,p]),ne=u(ke),Te=n(()=>{s(!1),i.value=!1,o.current(v.Cancelled)},[s,i,o]),re=u(Te),Ie=n(({errorMessage:e})=>{s(!1),i.value=!1,p(new St(e))},[s,i,p]),k=u(Ie),Me=n(async e=>{b(),N.current?await N.current(e):k.current({errorMessage:"onApproveRef is not set"})},[N,k,b]),oe=u(Me),Re=n(async()=>{C.value=!1;try{B?await X():U?(t||J(),Q?.dispatch("addressReplaced")):await P({runListenersOnError:!0})}catch(e){p(e)}},[C,B,U,t,J,Q,p,X,P]),le=u(Re),Oe=n(async()=>{const e=a==="venmo",l=G.value;try{ee.value="PAYPAL_EXPRESS",O.value=!0,Z();const c=await yt({graphql:W,countryCode:D,email:l,venmoPayment:e,getNegotiationVariables:H,isPayWithPayPalFlow:t,telemetryClient:S,isPayPalPCIv4:!0});return t||j(),i.value=!1,y?{billingToken:c}:{orderId:c}}catch(c){throw s(!1),p(c),c}},[a,G.value,ee,O,Z,W,D,H,t,S,i,y,j,s,p]),ce=u(Oe),ie=ct(),_e=it(()=>({clicked:()=>ne.current(),cancelled:()=>re.current(),createOrder:()=>ce.current(),paymentFlowError:({errorMessage:e})=>k.current({errorMessage:e}),paymentApproved:e=>oe.current(e),negotiateOrProgressOnApprove:()=>le.current(),expandIFrame:se,telemetry:ie}),[ne,re,ce,k,oe,le,se,ie]);ut(()=>()=>{const e=a==="venmo"?_.peek().status:L.peek().status;e!=="error"&&e!=="not_eligible"&&g("not_rendered",a),O.peek()&&(R.value=!1),i.value=!1},[]);const Le=t?gt:void 0;return I?x(mt,{children:[x(pt,{wallet:ft,onConnect:Ce,hostMethods:_e,height:Le,isFullScreen:m.value,ref:w,rpcId:`${a}-${t?"pay":"express"}`}),x(dt,{isOpen:f.value&&!m.value,walletName:he,handleClose:Se})]}):(S.counter({name:"paypal_missing_client_token",value:1,attributes:{payWithPayPal:t,fundingSource:a}}),null)}export{ge as DISABLE_VIEW_TRANSITIONS_STYLE,St as PayPalPaymentFlowError,Tt as PaypalMissingConfigurationError,It as default};