import{cf as T,cd as $,ce as U,o as S,C as F,bL as _,cg as K,ch as f,a as s,a$ as j,cj as N,aQ as X,bH as G,eE as H,r4 as J,eB as Q,ih as Z,A as B,ii as q,q as z,is as I,it as O,T as V,r5 as Y,r6 as ee,r7 as x,iu as te,iv as ne,r8 as oe,cx as ae,fU as se,cB as re,cz as ie,r9 as ce,K as ue}from"./app.B46ok1sD.js";function le(){const e=T(),t=$(),n=U(),a=S(),i=F(),d=a("review.blocks.change_link_label"),{inMemoryAmazonPayParts:{hasPaymentSheetError:l}}=_();return!K()||t.status!==f.Available?null:s(j,{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}=X(),l=G(),{id:P}=n,{value:k}=H(),{countryCode:c,presentmentCurrency:p}=k??{},b=J(e)?.configurationParams,g=Q(null),{isScrimOpen:m,closePopupWindowsAndScrim:M}=Z({endpoint:g}),{inMemoryAmazonPayParts:{buttonStatus:w,sdkStatus:h}}=_(),E=S(),C=B(null),W=B(null),v=q(),y=z(({errorMessage:o})=>a.notify(new r(o)),[a]),L=z(async o=>{h.value={status:f.Loading},g.value=o;const u=await o.call.configure({configurationParams:b,buyerCountry:c,buyerCurrency:p,shopId:P,cartId:i.sourceId,onlySdk:t,service:d.services.portableWallets});u?.status===I.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===I.Error&&y({errorMessage:u?.message}),h.value={status:f.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,P,p,i.sourceId,t,e,y,h,w,g,d,l]),A=O(),D=V(()=>({clicked:o=>{m.value=!0,v(W),o&&fe(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"),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:f.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 fe(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 Pe(){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"),summary:i?s(ie,{}):s(ce,{brand:t,descriptor:n}),action:s(le,{})})]})}const ge=Object.freeze(Object.defineProperty({__proto__:null,default:Pe},Symbol.toStringTag,{value:"Module"}));export{he as P,ge as V};