import{cc as T,ca as $,cb as F,x as S,a7 as U,bE as _,cd as j,ce as P,a as s,aV as K,cg as N,aL as G,bA as X,eG as J,r8 as V,eD as Z,i6 as q,A as B,i7 as H,q as I,ih as z,ii as O,T as Q,r9 as Y,ra as ee,rb as x,ij as te,ik as ne,rc as oe,cw as ae,fL as se,cA as re,cy as ie,rd as ce,a6 as ue}from"./app.Dqw-tRcr.js";function le(){const e=T(),t=$(),n=F(),a=S(),i=U(),d=a("review.blocks.change_link_label","Change"),{inMemoryAmazonPayParts:{hasPaymentSheetError:l}}=_();return!j()||t.status!==P.Available?null:s(K,{onClick:()=>{try{t.sdk.buywithprime.changePaymentMethod({amazonPayOptions:{amazonCheckoutSessionId:n(),isDeclined:e}})}catch(c){l.value=!0,i.notify(new N(`Error on changing buyer payment method. Details: ${c}`,{cause:c}))}},children:d})}class r extends Error{name="PortableWalletsSandboxError"}const de="oZdJX",me={PortableWalletsPCIButton:de};function he({wallet:e,isSdkOnly:t=!1}){const{shop:n,errorLogger:a,source:i,environment:d}=G(),l=X(),{id:f}=n,{value:k}=J(),{countryCode:c,presentmentCurrency:p}=k??{},b=V(e)?.configurationParams,g=Z(null),{isScrimOpen:m,closePopupWindowsAndScrim:M}=q({endpoint:g}),{inMemoryAmazonPayParts:{buttonStatus:w,sdkStatus:h}}=_(),E=S(),C=B(null),W=B(null),v=H(),y=I(({errorMessage:o})=>a.notify(new r(o)),[a]),L=I(async o=>{h.value={status:P.Loading},g.value=o;const u=await o.call.configure({configurationParams:b,buyerCountry:c,buyerCurrency:p,shopId:f,cartId:i.sourceId,onlySdk:t,service:d.services.portableWallets});u?.status===z.Success?(h.value=ye(e,o),t||(w.value={status:"rendered"},l.counter({name:"checkout_wallet_button_rendered",value:1,attributes:{wallet_name:e,status:"success",isPaymentMethodFlow:!1}}))):(u?.status===z.Error&&y({errorMessage:u?.message}),h.value={status:P.Error},t||(w.value={status:"error"},l.counter({name:"checkout_wallet_button_rendered",value:1,attributes:{wallet_name:e,status:"error",isPaymentMethodFlow:!1}})))},[b,c,f,p,i.sourceId,t,e,y,h,w,g,d,l]),A=O(),D=Q(()=>({clicked:o=>{m.value=!0,v(W),o&&Pe(o.skus,o.apiClientId)},closed:()=>m.value=!1,redirect:({redirectUrl:o,requestPayload:u})=>{try{if(u){if(!C.current){a.notify(new Y("Form container not found"));return}ee({formContainer:C.current,url:o,requestPayload:u}).submit()}else window.location.assign(o)}catch(R){a.notify(R)}},reportError:y,telemetry:A}),[m,y,a,v,A]);return b?!c||!p?(a.notify(new x(`[PortableWalletsButton] Attempted to render wallet button for ${e}, but no countryCode or presentmentCurrency was found.`)),null):s("div",{className:me.PortableWalletsPCIButton,children:[s("div",{ref:C,style:{display:"none"}}),s(te,{wallet:e,onConnect:L,hostMethods:D,isSdkOnly:t,ref:W}),s(ne,{isOpen:m.value,walletName:E("brand.buy_with_prime","Buy with Prime"),handleClose:M})]}):(a.notify(new x(`[PortableWalletsButton] Attempted to render wallet button for ${e}, but no config was found.`)),null)}function ye(e,t){return{status:P.Available,sdk:{buywithprime:{changePaymentMethod:({amazonPayOptions:n})=>{if(!n.amazonCheckoutSessionId)throw new r("Missing amazonCheckoutSessionId");t.call.changePaymentMethod({wallet:e,changePaymentParams:{amazonCheckoutSessionId:n.amazonCheckoutSessionId,isDeclined:n.isDeclined}})},changeShippingAddress:({amazonPayOptions:n})=>{if(!n.amazonCheckoutSessionId)throw new r("Missing amazonCheckoutSessionId");t.call.changeShippingAddress({wallet:e,changeShippingParams:{amazonCheckoutSessionId:n.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,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 fe(){const e=S(),{brand:t,descriptor:n}=oe(),a=ae(),i=!n||!a;return s(ue,{children:[s(he,{wallet:se.BuyWithPrime,isSdkOnly:!0}),s(re,{id:"buyWithPrimePayDetails",label:e("payment.payment_method","Payment method"),summary:i?s(ie,{}):s(ce,{brand:t,descriptor:n}),action:s(le,{})})]})}const ge=Object.freeze(Object.defineProperty({__proto__:null,default:fe},Symbol.toStringTag,{value:"Module"}));export{he as P,ge as V};