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,lz as N,fv as j,hH as G,ec as X,ef as H,al as A,el as J,b3 as I,es as z,et as Q,bQ as Z,qw as O,qx as V,hI as B,ew as Y,f2 as ee,qy as ne,co as te,hK as oe,gv as ae,cs as se,cq as re,qz as ie,G as ce}from"./app.B7V4PU1H.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}=N(),{id:d}=t,{value:S}=j(),{countryCode:h,presentmentCurrency:l}=S??{},p=G(e)?.configurationParams,b=X(null),{isScrimOpen:m,closePopupWindowsAndScrim:E}=H({endpoint:b}),{inMemoryAmazonPayParts:{buttonStatus:g,sdkStatus:y}}=x(),M=w(),C=A(null),k=A(null),v=J(),f=I(({errorMessage:o})=>a.notify(new r(o)),[a]),D=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===z.Success?(y.value=me(e,o),n||(g.value={status:"rendered"})):(u?.status===z.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]),W=Q(),L=Z(()=>({clicked:o=>{m.value=!0,v(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:W}),[m,f,a,v,W]);return p?!h||!l?(a.notify(new B(`[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:D,hostMethods:L,isSdkOnly:n,ref:k}),s(ee,{isOpen:m.value,walletName:M("brand.buy_with_prime","Buy with Prime"),handleClose:E})]}):(a.notify(new B(`[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};