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