import{c3 as R,c1 as T,c2 as $,i as w,a2 as q,bf as x,c4 as U,c5 as P,a as s,aC as K,c7 as F,lB as J,fv as N,hI as j,ec as G,ef as X,al as A,el as Q,b3 as I,es as B,et as Z,bQ as H,qJ as O,qK as V,hJ as z,ew as Y,fe as ee,qL as ne,co as te,hL as oe,gw as ae,cs as se,cq as re,qM as ie,G as ce}from"../../app.WrdOEiRI.js";function le(){const e=R(),n=T(),t=$(),a=w(),i=q(),c=a("review.blocks.change_link_label","Change"),{inMemoryAmazonPayParts:{hasPaymentSheetError:d}}=x();return!U()||n.status!==P.Available?null:s(K,{onClick:()=>{try{n.sdk.buywithprime.changePaymentMethod({amazonPayOptions:{amazonCheckoutSessionId:t(),isDeclined:e}})}catch(l){d.value=!0,i.notify(new F(`Error on changing buyer payment method. Details: ${l}`,{cause:l}))}},children:c})}class r extends Error{name="PortableWalletsSandboxError"}const ue="oZdJX",de={PortableWalletsPCIButton:ue};function he({wallet:e,isSdkOnly:n=!1}){const{shop:t,errorLogger:a,source:i,environment:c}=J(),{id:d}=t,{value:S}=N(),{countryCode:h,presentmentCurrency:l}=S??{},p=j(e)?.configurationParams,b=G(null),{isScrimOpen:m,closePopupWindowsAndScrim:M}=X({endpoint:b}),{inMemoryAmazonPayParts:{buttonStatus:g,sdkStatus:y}}=x(),E=w(),C=A(null),k=A(null),W=Q(),f=I(({errorMessage:o})=>a.notify(new r(o)),[a]),L=I(async o=>{y.value={status:P.Loading},b.value=o;const u=await o.call.configure({configurationParams:p,buyerCountry:h,buyerCurrency:l,shopId:d,cartId:i.sourceId,onlySdk:n,service:c.services.portableWallets});u?.status===B.Success?(y.value=me(e,o),n||(g.value={status:"rendered"})):(u?.status===B.Error&&f({errorMessage:u?.message}),y.value={status:P.Error},n||(g.value={status:"error"}))},[p,h,d,l,i.sourceId,n,e,f,y,g,b,c]),v=Z(),D=H(()=>({clicked:o=>{m.value=!0,W(k),o&&ye(o.skus,o.apiClientId)},closed:()=>m.value=!1,redirect:({redirectUrl:o,requestPayload:u})=>{try{if(u){if(!C.current){a.notify(new O("Form container not found"));return}V({formContainer:C.current,url:o,requestPayload:u}).submit()}else window.location.assign(o)}catch(_){a.notify(_)}},reportError:f,telemetry:v}),[m,f,a,W,v]);return p?!h||!l?(a.notify(new z(`[PortableWalletsButton] Attempted to render wallet button for ${e}, but no countryCode or presentmentCurrency was found.`)),null):s("div",{className:de.PortableWalletsPCIButton,children:[s("div",{ref:C,style:{display:"none"}}),s(Y,{wallet:e,onConnect:L,hostMethods:D,isSdkOnly:n,ref:k}),s(ee,{isOpen:m.value,walletName:E("brand.buy_with_prime","Buy with Prime"),handleClose:M})]}):(a.notify(new z(`[PortableWalletsButton] Attempted to render wallet button for ${e}, but no config was found.`)),null)}function me(e,n){return{status:P.Available,sdk:{buywithprime:{changePaymentMethod:({amazonPayOptions:t})=>{if(!t.amazonCheckoutSessionId)throw new r("Missing amazonCheckoutSessionId");n.call.changePaymentMethod({wallet:e,changePaymentParams:{amazonCheckoutSessionId:t.amazonCheckoutSessionId,isDeclined:t.isDeclined}})},changeShippingAddress:({amazonPayOptions:t})=>{if(!t.amazonCheckoutSessionId)throw new r("Missing amazonCheckoutSessionId");n.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 ye(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}=ne(),a=te(),i=oe(),c=!t||!a;return s(ce,{children:[i?s(he,{wallet:ae.BuyWithPrime,isSdkOnly:!0}):null,s(se,{id:"buyWithPrimePayDetails",label:e("payment.payment_method","Payment method"),summary:c?s(re,{}):s(ie,{brand:n,descriptor:t}),action:s(le,{})})]})}const be=Object.freeze(Object.defineProperty({__proto__:null,default:fe},Symbol.toStringTag,{value:"Module"}));export{he as P,be as V};