import{c3 as R,c1 as T,c2 as $,i as w,a2 as z,bf as B,c4 as q,c5 as f,a as s,aC as U,c7 as K,bk as F,bu as G,fv as N,hG as j,ec as J,ef as X,al as W,el as H,b3 as v,es as A,et as Q,bQ as Z,qw as O,qx as V,hH as I,ew as Y,eK as ee,qy as ne,co as te,hJ as oe,gv as ae,cs as se,cq as re,qz as ie,G as ce}from"./app.BVDiBddt.js";function ue(){const e=R(),n=T(),t=$(),a=w(),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}=F(),a=z(),i=G(),{value:l}=N(),{countryCode:d,presentmentCurrency:h}=l??{},c=j(e)?.configurationParams,p=J(null),{isScrimOpen:m,closePopupWindowsAndScrim:E}=X({endpoint:p}),{inMemoryAmazonPayParts:{buttonStatus:b,sdkStatus:y}}=B(),M=w(),g=W(null),C=W(null),S=H(),P=v(({errorMessage:o})=>a.notify(new r(o)),[a]),D=v(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===A.Success?(y.value=me(e,o),n||(b.value={status:"rendered"})):(u?.status===A.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=Q(),_=Z(()=>({clicked:o=>{m.value=!0,S(C),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(L){a.notify(L)}},reportError:P,telemetry:k}),[m,P,a,S,k]);return c?!d||!h?(a.notify(new I(`[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:_,isSdkOnly:n,ref:C}),s(ee,{isOpen:m.value,walletName:M("brand.buy_with_prime","Buy with Prime"),handleClose:E})]}):(a.notify(new I(`[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=w(),{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};