import{c3 as R,c1 as T,c2 as $,i as C,a2 as z,b7 as B,c4 as q,c5 as f,a as s,aC as U,c7 as K,bk as N,bl as F,fy as X,hK as j,ed as G,eg as J,al as W,em as Q,aX as A,et as I,eu as Z,bQ as H,qx as O,qy as V,hL as v,ex as Y,f5 as ee,qz as ne,co as te,hN as oe,gy as ae,cs as se,cq as re,qA as ie,G as ce}from"./app.DGBnFLnj.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!==f.Available?null:s(U,{onClick:()=>{try{n.sdk.buywithprime.changePaymentMethod({amazonPayOptions:{amazonCheckoutSessionId:t(),isDeclined:e}})}catch(c){d.value=!0,i.notify(new K(`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}=N(),a=z(),i=F(),{value:l}=X(),{countryCode:d,presentmentCurrency:h}=l??{},c=j(e)?.configurationParams,p=G(null),{isScrimOpen:m,closePopupWindowsAndScrim:E}=J({endpoint:p}),{inMemoryAmazonPayParts:{buttonStatus:b,sdkStatus:y}}=B(),M=C(),g=W(null),S=W(null),w=Q(),P=A(({errorMessage:o})=>a.notify(new r(o)),[a]),D=A(async o=>{y.value={status:f.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&&P({errorMessage:u?.message}),y.value={status:f.Error},n||(b.value={status:"error"}))},[c,d,t,h,i.sourceId,n,e,P,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:P,telemetry:k}),[m,P,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:f.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 Pe(){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:Pe},Symbol.toStringTag,{value:"Module"}));export{he as P,pe as V};