import{u as o,o as z,A as B,q as I,T as F,b as T}from"./vendor.CynPCimz.js";import{bc as N,v4 as U,v5 as $,b as g,v6 as K,aN as E,c3 as b,L as V,v7 as X,c4 as j,lz as Y,v8 as H,iP as J,iQ as O,iW as x,iX as Q,v9 as Z,va as q,iY as G,vb as ee,vc as te,c8 as ne,c1 as ae,ca as oe,aw as se,vd as re}from"./app.BXvw8ij6.js";function ie(){const{hasError:e}=N(j),t=U(),n=$(),{i18n:u,telemetryClient:l}=g(),m=u.translate("review.blocks.change_link_label"),s=K(n?.method?.walletParams)?.checkout_session_id,{inMemoryAmazonPayParts:{hasPaymentSheetError:h}}=E();return!n||t.status!==b.Available?null:o(V,{onClick:()=>{try{t.sdk.buywithprime.changePaymentMethod({amazonPayOptions:{amazonCheckoutSessionId:s,isDeclined:e}})}catch(d){h.value=!0,l.error(new X(`Error on changing buyer payment method. Details: ${d}`,{cause:d}))}},children:m})}class r extends Error{name="PortableWalletsSandboxError"}const le="oZdJX",ce={PortableWalletsPCIButton:le};function ue({wallet:e,isSdkOnly:t=!1}){const{i18n:n,shop:u,source:l,environment:m,telemetryClient:s}=g(),{id:h}=u,{value:y}=Y(),{countryCode:d,presentmentCurrency:S}=y??{},k=H(e)?.configurationParams,i=z(null),{isScrimOpen:P,closePopupWindowsAndScrim:M}=J({endpoint:i,invokingWallet:e}),{inMemoryAmazonPayParts:{buttonStatus:v,sdkStatus:p}}=E(),w=B(null),W=B(null),A=O(),f=I(({errorMessage:a})=>s.error(new r(a)),[s]),C=z(!1),R=I(async a=>{p.value={status:b.Loading};const c=await a.call.configure({configurationParams:k,buyerCountry:d,buyerCurrency:S,shopId:h,cartId:l.sourceId,onlySdk:t,service:m.services.portableWallets});c?.status===x.Success?(p.value=de(e,i),t||(v.value={status:"rendered"},s.counter({name:"checkout_wallet_button_rendered",value:1,attributes:{wallet_name:e,status:"success",isPaymentMethodFlow:!1}}))):(c?.status===x.Error&&f({errorMessage:c?.message}),p.value={status:b.Error},t||(v.value={status:"error"},s.counter({name:"checkout_wallet_button_rendered",value:1,attributes:{wallet_name:e,status:"error",isPaymentMethodFlow:!1}})))},[k,d,h,S,l.sourceId,t,e,f,p,v,i,m,s]);C.value&&y?.countryCode&&y?.presentmentCurrency&&i.value&&(C.value=!1,R(i.value));const _=Q(),D=F(()=>({clicked:a=>{P.value=!0,A(W),a&&me(a.skus,a.apiClientId)},closed:()=>P.value=!1,redirect:({redirectUrl:a,requestPayload:c})=>{try{if(c){if(!w.current){s.error(new Z("Form container not found",{groupingHash:"AmazonPaySandboxError::PortableWalletsPCIButton::FormContainerNotFound"}));return}q({formContainer:w.current,url:a,requestPayload:c}).submit()}else window.location.assign(a)}catch(L){s.error(L)}},reportError:f,telemetry:_}),[P,f,s,A,_]);return o("div",{className:ce.PortableWalletsPCIButton,children:[o("div",{ref:w,style:{display:"none"}}),o(G,{wallet:e,onConnect:a=>{i.value=a,C.value=!0},onTerminate:()=>i.value=null,hostMethods:D,isSdkOnly:t,ref:W}),o(ee,{isOpen:P.value,walletName:n.translate("brand.buy_with_prime"),handleClose:M})]})}function de(e,t){return{status:b.Available,sdk:{buywithprime:{changePaymentMethod:({amazonPayOptions:n})=>{if(!n.amazonCheckoutSessionId)throw new r("Missing amazonCheckoutSessionId");t.value?.call.changePaymentMethod({wallet:e,changePaymentParams:{amazonCheckoutSessionId:n.amazonCheckoutSessionId,isDeclined:n.isDeclined}})},changeShippingAddress:({amazonCheckoutSessionId:n})=>{if(!n)throw new r("Missing amazonCheckoutSessionId");t.value?.call.changeShippingAddress({wallet:e,changeShippingParams:{amazonCheckoutSessionId:n}})},initCheckout:()=>{throw new r('Unexpected invocation of "initCheckout"')},renderButton:()=>{throw new r('Unexpected invocation of "renderButton"')}},Pay:{changePaymentMethod:()=>{throw new r('Unexpected invocation of AmazonPay "changePaymentMethod" in BWP flow')},changeShippingAddress:()=>{throw new r('Unexpected invocation of AmazonPay "changeShippingAddress" in BWP flow')},initCheckout:()=>{throw new r('Unexpected invocation of AmazonPay "initCheckout" in BWP flow')},renderButton:()=>{throw new r('Unexpected invocation of AmazonPay "renderButton" in BWP flow')}}}}}function me(e,t){window.Shopify?.analytics?.publish&&(window.Shopify.analytics.publish(`shopify:app:pixels:load:${t}`,{},{sendTo:"PIXEL-LOADER"}),window.Shopify.analytics.publish("bwp_checkout_widget_click",{skus:e},{sendTo:t}))}function he(){const{i18n:e}=g(),{brand:t,descriptor:n}=te(),u=ne(),l=!n||!u;return o(T,{children:[o(ue,{wallet:ae.BuyWithPrime,isSdkOnly:!0}),o(oe,{id:"buyWithPrimePayDetails",label:e.translate("payment.payment_method"),summary:l?o(se,{}):o(re,{brand:t,descriptor:n}),action:o(ie,{})})]})}const fe=Object.freeze(Object.defineProperty({__proto__:null,default:he},Symbol.toStringTag,{value:"Module"}));export{ue as P,fe as V};
