import{u as s,p as z,A as B,q as x,T as L,k as T}from"./dist-vendor.a3kfnPsb.js";import{ap as N,lp as U,lq as V,X as j,lr as X,f4 as $,fa as I,fb as K,ls as q,fc as H,lt as J,i2 as O,lu as Y,jj as Z,i_ as G,a3 as Q,lv as ee}from"./shop-pay-ButtonWithRegisterWebPixel.CUNg0UCj.js";import{ky as te,a as w,kz as ne,l as E,kA as b,b as ae,kB as oe,cl as se,kC as re,aX as ie}from"./shop-pay-FullScreenBackground.Bxb6RI8a.js";function le(){const{hasError:e}=N(te),t=U(),n=V(),{i18n:l,observability:u}=w(),d=l.translate("review.blocks.change_link_label"),a=ne(n.value?.method?.walletParams)?.checkout_session_id,{inMemoryAmazonPayParts:{hasPaymentSheetError:h}}=E();return!n.value||t.status!==b.Available?null:s(j,{onClick:()=>{try{t.sdk.buywithprime.changePaymentMethod({amazonPayOptions:{amazonCheckoutSessionId:a,isDeclined:e}})}catch(m){h.value=!0,u.error(new X(`Error on changing buyer payment method. Details: ${m}`,{cause:m}))}},children:d})}class r extends Error{constructor(){super(...arguments),this.name="PortableWalletsSandboxError"}}const ue="oZdJX",ce={PortableWalletsPCIButton:ue};function de({wallet:e,isSdkOnly:t=!1}){const{i18n:n,shop:l,source:u,environment:d,observability:a}=w(),{id:h}=l,{value:y}=ae().buyerIdentity,{countryCode:m,presentmentCurrency:S}=y??{},k=oe(e).value?.configurationParams,i=z(null),{isScrimOpen:p,closePopupWindowsAndScrim:M}=$({endpoint:i,invokingWallet:e}),{inMemoryAmazonPayParts:{buttonStatus:g,sdkStatus:P}}=E(),v=B(null),A=B(null),W=se(),f=x(({errorMessage:o})=>a.error(new r(o)),[a]),C=z(!1),R=x(async o=>{P.value={status:b.Loading};const c=await o.call.configure({configurationParams:k,buyerCountry:m,buyerCurrency:S,shopId:h,cartId:u.sourceId,onlySdk:t,service:d.services.portableWallets});c?.status===I.Success?(P.value=me(e,i),t||(g.value={status:"rendered"},a.counter({name:"checkout_wallet_button_rendered",value:1,attributes:{wallet_name:e,status:"success",isPaymentMethodFlow:!1}}))):(c?.status===I.Error&&f({errorMessage:c?.message}),P.value={status:b.Error},t||(g.value={status:"error"},a.counter({name:"checkout_wallet_button_rendered",value:1,attributes:{wallet_name:e,status:"error",isPaymentMethodFlow:!1}})))},[k,m,h,S,u.sourceId,t,e,f,P,g,i,d,a]);C.value&&y?.countryCode&&y?.presentmentCurrency&&i.value&&(C.value=!1,R(i.value));const _=K(),D=L(()=>({clicked:o=>{p.value=!0,W(A),o&&he(o.skus,o.apiClientId)},closed:()=>p.value=!1,redirect:({redirectUrl:o,requestPayload:c})=>{try{if(c){if(!v.current){a.error(new q("Form container not found",{groupingHash:"AmazonPaySandboxError::PortableWalletsPCIButton::FormContainerNotFound"}));return}re({formContainer:v.current,url:o,requestPayload:c}).submit()}else window.location.assign(o)}catch(F){a.error(F)}},reportError:f,telemetry:_}),[p,f,a,W,_]);return s("div",{className:ce.PortableWalletsPCIButton,children:[s("div",{ref:v,style:{display:"none"}}),s(H,{wallet:e,onConnect:o=>{i.value=o,C.value=!0},onTerminate:()=>i.value=null,hostMethods:D,isSdkOnly:t,ref:A}),s(J,{isOpen:p,walletName:n.translate("brand.buy_with_prime"),handleClose:M})]})}function me(e,t){return{status:b.Available,sdk:{buywithprime:{changePaymentMethod:({amazonPayOptions:n})=>{if(!n.amazonCheckoutSessionId)throw new r("Missing amazonCheckoutSessionId");t.value?.call.changePaymentMethod({wallet:e,changePaymentParams:{amazonCheckoutSessionId:n.amazonCheckoutSessionId,isDeclined:n.isDeclined}})},changeShippingAddress:({amazonCheckoutSessionId:n})=>{if(!n)throw new r("Missing amazonCheckoutSessionId");t.value?.call.changeShippingAddress({wallet:e,changeShippingParams:{amazonCheckoutSessionId:n}})},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 he(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 ye(){const{i18n:e}=w(),t=O()==="treatment",{brand:n,descriptor:l}=Y().value,u=Z(),a=!l||!u?s(Q,{}):s(ee,{brand:n,descriptor:l});return s(T,{children:[s(de,{wallet:ie.BuyWithPrime,isSdkOnly:!0}),s(G,{id:"buyWithPrimePayDetails",label:t?e.translate("payment.title"):e.translate("payment.payment_method"),summary:a,primaryContent:a,action:s(le,{}),section:"payment"})]})}const ge=Object.freeze(Object.defineProperty({__proto__:null,default:ye},Symbol.toStringTag,{value:"Module"}));export{de as P,ge as V};
