import{cd as j,cb as F,cc as U,e as w,i as $,br as M,ce as N,cf as p,a as o,bP as K,ch as V,ao as H,aW as O,hO as X,so as q,gC as z,jF as G,aj as B,jH as J,q as x,jP as _,jQ as Q,bO as Z,sp as Y,sq as ee,jR as ne,sr as te,ss as ae,cv as oe,f$ as se,cy as re,bg as ie,st as ce,n as le}from"./app.owqgWGYv.js";function ue(){const e=j(),n=F(),t=U(),s=w(),c=$(),m=s("review.blocks.change_link_label"),{inMemoryAmazonPayParts:{hasPaymentSheetError:u}}=M();return!N()||n.status!==p.Available?null:o(K,{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}=H(),u=O(),{id:b}=t,{value:h}=X(),{countryCode:d,presentmentCurrency:v}=h??{},k=q(e)?.configurationParams,i=z(null),{isScrimOpen:y,closePopupWindowsAndScrim:E}=G({endpoint:i,invokingWallet:e}),{inMemoryAmazonPayParts:{buttonStatus:g,sdkStatus:P}}=M(),D=w(),C=B(null),W=B(null),A=J(),f=x(({errorMessage:a})=>s.notify(new r(a)),[s]),S=z(!1),L=x(async a=>{P.value={status:p.Loading};const l=await a.call.configure({configurationParams:k,buyerCountry:d,buyerCurrency:v,shopId:b,cartId:c.sourceId,onlySdk:n,service:m.services.portableWallets});l?.status===_.Success?(P.value=ye(e,i),n||(g.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||(g.value={status:"error"},u.counter({name:"checkout_wallet_button_rendered",value:1,attributes:{wallet_name:e,status:"error",isPaymentMethodFlow:!1}})))},[k,d,b,v,c.sourceId,n,e,f,P,g,i,m,u]);S.value&&h?.countryCode&&h?.presentmentCurrency&&i.value&&(S.value=!1,L(i.value));const I=Q(),R=Z(()=>({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(T){s.notify(T)}},reportError:f,telemetry:I}),[y,f,s,A,I]);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:R,isSdkOnly:n,ref:W}),o(te,{isOpen:y.value,walletName:D("brand.buy_with_prime"),handleClose:E})]})}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 ge=Object.freeze(Object.defineProperty({__proto__:null,default:fe},Symbol.toStringTag,{value:"Module"}));export{he as P,ge as V};