import{cd as F,cb as R,cc as U,c as w,g as K,br as E,ce as N,cf as p,a as o,L as $,ch as V,at as X,aW as q,jK as G,sA as H,hk as B,jp as J,ao as I,jq as Z,q as x,jz as _,jA as O,bP as Q,sB as Y,sC as ee,jB as ne,sD as te,sE as ae,cv as oe,g6 as se,cy as re,bg as ie,sF as ce,l as le}from"./app.BTSv6d-3.js";function ue(){const e=F(),n=R(),t=U(),s=w(),c=K(),m=s("review.blocks.change_link_label"),{inMemoryAmazonPayParts:{hasPaymentSheetError:u}}=E();return!N()||n.status!==p.Available?null:o($,{onClick:()=>{try{n.sdk.buywithprime.changePaymentMethod({amazonPayOptions:{amazonCheckoutSessionId:t(),isDeclined:e}})}catch(d){u.value=!0,c.notify(new V(`Error on changing buyer payment method. Details: ${d}`,{cause:d}))}},children:m})}class r extends Error{name="PortableWalletsSandboxError"}const de="oZdJX",me={PortableWalletsPCIButton:de};function he({wallet:e,isSdkOnly:n=!1}){const{shop:t,errorLogger:s,source:c,environment:m}=X(),u=q(),{id:g}=t,{value:h}=G(),{countryCode:d,presentmentCurrency:v}=h??{},k=H(e)?.configurationParams,i=B(null),{isScrimOpen:y,closePopupWindowsAndScrim:M}=J({endpoint:i,invokingWallet:e}),{inMemoryAmazonPayParts:{buttonStatus:b,sdkStatus:P}}=E(),D=w(),C=I(null),W=I(null),A=Z(),f=x(({errorMessage:a})=>s.notify(new r(a)),[s]),S=B(!1),L=x(async a=>{P.value={status:p.Loading};const l=await a.call.configure({configurationParams:k,buyerCountry:d,buyerCurrency:v,shopId:g,cartId:c.sourceId,onlySdk:n,service:m.services.portableWallets});l?.status===_.Success?(P.value=ye(e,i),n||(b.value={status:"rendered"},u.counter({name:"checkout_wallet_button_rendered",value:1,attributes:{wallet_name:e,status:"success",isPaymentMethodFlow:!1}}))):(l?.status===_.Error&&f({errorMessage:l?.message}),P.value={status:p.Error},n||(b.value={status:"error"},u.counter({name:"checkout_wallet_button_rendered",value:1,attributes:{wallet_name:e,status:"error",isPaymentMethodFlow:!1}})))},[k,d,g,v,c.sourceId,n,e,f,P,b,i,m,u]);S.value&&h?.countryCode&&h?.presentmentCurrency&&i.value&&(S.value=!1,L(i.value));const z=O(),T=Q(()=>({clicked:a=>{y.value=!0,A(W),a&&Pe(a.skus,a.apiClientId)},closed:()=>y.value=!1,redirect:({redirectUrl:a,requestPayload:l})=>{try{if(l){if(!C.current){s.notify(new Y("Form container not found",{groupingHash:"AmazonPaySandboxError::PortableWalletsPCIButton::FormContainerNotFound"}));return}ee({formContainer:C.current,url:a,requestPayload:l}).submit()}else window.location.assign(a)}catch(j){s.notify(j)}},reportError:f,telemetry:z}),[y,f,s,A,z]);return o("div",{className:me.PortableWalletsPCIButton,children:[o("div",{ref:C,style:{display:"none"}}),o(ne,{wallet:e,onConnect:a=>{i.value=a,S.value=!0},onTerminate:()=>i.value=null,hostMethods:T,isSdkOnly:n,ref:W}),o(te,{isOpen:y.value,walletName:D("brand.buy_with_prime"),handleClose:M})]})}function ye(e,n){return{status:p.Available,sdk:{buywithprime:{changePaymentMethod:({amazonPayOptions:t})=>{if(!t.amazonCheckoutSessionId)throw new r("Missing amazonCheckoutSessionId");n.value?.call.changePaymentMethod({wallet:e,changePaymentParams:{amazonCheckoutSessionId:t.amazonCheckoutSessionId,isDeclined:t.isDeclined}})},changeShippingAddress:({amazonPayOptions:t})=>{if(!t.amazonCheckoutSessionId)throw new r("Missing amazonCheckoutSessionId");n.value?.call.changeShippingAddress({wallet:e,changeShippingParams:{amazonCheckoutSessionId:t.amazonCheckoutSessionId}})},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 Pe(e,n){window.Shopify?.analytics?.publish&&(window.Shopify.analytics.publish(`shopify:app:pixels:load:${n}`,{},{sendTo:"PIXEL-LOADER"}),window.Shopify.analytics.publish("bwp_checkout_widget_click",{skus:e},{sendTo:n}))}function fe(){const e=w(),{brand:n,descriptor:t}=ae(),s=oe(),c=!t||!s;return o(le,{children:[o(he,{wallet:se.BuyWithPrime,isSdkOnly:!0}),o(re,{id:"buyWithPrimePayDetails",label:e("payment.payment_method"),summary:c?o(ie,{}):o(ce,{brand:n,descriptor:t}),action:o(ue,{})})]})}const be=Object.freeze(Object.defineProperty({__proto__:null,default:fe},Symbol.toStringTag,{value:"Module"}));export{he as P,be as V};