var _____WB$wombat$assign$function_____=function(name){return (globalThis._wb_wombat && globalThis._wb_wombat.local_init && globalThis._wb_wombat.local_init(name))||globalThis[name];};if(!globalThis.__WB_pmw){globalThis.__WB_pmw=function(obj){this.__WB_source=obj;return this;}}var window = _____WB$wombat$assign$function_____("window");
var self = _____WB$wombat$assign$function_____("self");
var document = _____WB$wombat$assign$function_____("document");
var location = _____WB$wombat$assign$function_____("location");
var top = _____WB$wombat$assign$function_____("top");
var parent = _____WB$wombat$assign$function_____("parent");
var frames = _____WB$wombat$assign$function_____("frames");
var opener = _____WB$wombat$assign$function_____("opener");
import{cc as R,ca as T,cb as $,i as C,a2 as z,b7 as B,cd as q,ce as f,a as s,aC as U,cg as F,bk as K,bl as N,hk as X,hC as j,ed as G,ee as Z,al as W,eg as J,aX as A,en as I,ep as H,bZ as O,qe as Q,qf as V,hD as v,eq as Y,er as ee,qg as ne,cx as te,hF as oe,gn as ae,cB as se,cz as re,qh as ie,G as ce}from"./app.ZXowmuNl.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 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}=X(),{countryCode:d,presentmentCurrency:h}=l??{},c=j(e)?.configurationParams,p=G(null),{isScrimOpen:m,closePopupWindowsAndScrim:E}=Z({endpoint:p}),{inMemoryAmazonPayParts:{buttonStatus:b,sdkStatus:y}}=B(),M=C(),g=W(null),S=W(null),w=J(),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=H(),_=O(()=>({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 Q("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,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:_,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};