import{w as e,p as n,m as t,u as a,M as s,D as i,G as r,h as l,t as o,v as d,T as c,q as u,N as m,o as p,s as b}from"./2c1ab0fe.Dbn2KvkT.js";import{dX as v,dY as h,dl as f,dZ as y,d_ as _,d$ as g,S,H as P,f as w,b6 as I,b8 as A,b9 as L,k as j,e0 as C,U as M,a7 as k,b as N,c9 as O,w as T,co as E,d as x}from"./164ad2e3.FTBuhkTQ.js";import{i as H,d as F,e as B,j as R}from"./86720dbb.Ctpif1U0.js";import{d as Y,d4 as q,I as D,d5 as V,_ as z,K as W,aK as U,d6 as K}from"./4b4bc88f.z1yoAwwH.js";import{j as Z,D as G}from"./6bfea526.D62LLGBP.js";import{b as J}from"./58314944.C8o0ZBBk.js";import{c as Q}from"./bf513f9c.B3u9Jber.js";import{a as X}from"./7a8217fd.qHfhLK3T.js";import{B as $}from"./b9c0319a.CZrWIGzl.js";import{a as ee,b as ne,C as te}from"./efa0389a.BBF5Yj3v.js";import{j as ae,k as se}from"./dffdfb34.BM70-hlD.js";import{S as ie}from"./0e67bd3b.rVVcKKmW.js";import{u as re}from"./cc6ff67d.CxMx1fOJ.js";import{C as le}from"./4b1c22b7.Tf9Z0cR8.js";import{C as oe}from"./a422df8c.Cf87EYCO.js";import{d as de,e as ce}from"./f8706cb6.H5idtf8V.js";import{g as ue}from"./65f3d4da.Bb3QiqCm.js";import{g as me}from"./ddf59287._uCuCuxL.js";import{S as pe}from"./3d539943.CHiZMBrZ.js";import{I as be}from"./17e57de1.C4OivbHV.js";function ve({selectorShowsTiles:r,afterPaymentSelector:l,renderVaultingAgreementInline:o}){const d=J(),c=v(),{checkout:u,i18n:m,shopPay:p,source:b}=Y(),I=h(),A=f(),L=y(),{paymentMethods:j}=u.negotiator.current.fields,C=p.user.creditCards,M=e(X().creditCardDisabled),k=n(null),N=t(()=>!(I.value||_({checkout:u,source:b})?.pickupAddress)&&!A.value&&u.isShippingRequired.value),O=t(()=>function({identity:e},{billingPosition:n,vaultedSections:t,showBillingAddressInContext:a}){switch(e.current.value){case"shopPay":return"inContext"===n.value&&!t.value.payment;case"businessCustomer":return!0;default:return a.value}}({identity:u.identity},{billingPosition:c,vaultedSections:L,showBillingAddressInContext:N})),T=t(()=>Z({paymentMethods:j.value})),E=g(),x=t(()=>Q({checkout:u,shopPay:p})?null:function({identity:e,i18n:n},{paymentMethodMustSupportInterestBearingLoans:t,supportedCountryOptions:a,creditCards:s,creditCardDisabled:i}){if("shopPay"!==e.current.value)return null;if(!t)return null;if(!s.every(e=>i(e)))return null;const r=a.map(e=>e.label).join(", ");return r?n.translate("installments.installments_debit_cards_supported_countries",{countries:r}):n.translate("installments.installments_valid_debit_cards_fallback")}({identity:u.identity,i18n:E},{paymentMethodMustSupportInterestBearingLoans:u.installments.paymentMethodMustSupportInterestBearingLoans.value,supportedCountryOptions:u.installments.supportedCountryOptions.value,creditCards:C.value,creditCardDisabled:M.value})),B=a(G,{blurValidationFieldDenylist:T.value,onSetFieldErrors:d,children:[a(H,{vaultHandle:k}),a(S,{gap:"base",children:[a(he,{}),a(F,{billingAddressInContext:O.value,vaultHandle:k,selectorShowsTiles:r,afterPaymentSelector:l,renderVaultingAgreementInline:o})]})]});return a(i,{when:x,fallback:B,children:e=>a(s,{children:[a(S,{gap:"small-400",children:[a(P,{level:2,children:m.translate("credit_card_form.add_debit_card")}),a(w,{color:"subdued",children:e})]}),B]})})}function he(){return B(),null}const fe="shipping_address",ye="custom_billing_address";function _e({renderFormOnly:e=!1}={}){const{i18n:n,checkout:{negotiator:t}}=Y(),s=I(),{billingAddressOption:d}=t.parts,c=A(),u="shipping"===d.value?fe:ye,[m,p]=r([u]),{isBilling:b}=ae().value,v=b?a(se,{}):null;l(()=>{p([u])},[u]);const h=o(e=>{const n=e[0]===fe?"shipping":"custom";d.value=n,p(e),"shipping"===n&&c()},[d,c]);L();const f=o(({billing:e})=>{e.value=!0},[]),y=o(({billing:e})=>{e.value=!1},[]);return a(i,{when:()=>!e&&"form"!==s.value,fallback:a(ie,{onValid:f,onInvalid:y,children:a(R,{children:v})}),children:a(ee,{name:"billing_address_selector",values:m,onChange:h,variant:"block",children:[a(ne,{value:fe,accessibilityLabel:n.translate("payment.same_billing_address_label"),children:a(j,{type:"strong",children:n.translate("payment.same_billing_address_label")})}),a(ne,{value:ye,selectedContent:a(ie,{onValid:f,onInvalid:y,children:a(R,{children:v})}),accessibilityLabel:n.translate("payment.different_billing_address_label"),children:a(j,{type:"strong",children:n.translate("payment.different_billing_address_label")})})]})})}const ge=()=>{const{i18n:e,checkout:{identity:n}}=Y(),t=Pe({identity:n});return a(S,{accessibilityRole:"group",accessibilityLabelledBy:"billingAddress",gap:"base",children:[a(P,{id:"billingAddress",level:2,children:e.translate("payment.billing_address_title")}),a(t,{})]})};function Se({dynamicPaymentExtensions:e=[],children:n}){C();const t=v(),i=f(),{checkout:r}=Y(),l=y(),o=q({checkout:r}),c=l.value.payment&&l.value.billing&&!o,[u]=re(),m=d(()=>Object.values(D).some(e=>u===e),[u]),p=!c&&!i.value&&!m;return a(S,{gap:"base",children:["beforePayment"===t.value&&p&&a(ge,{}),n,"afterPayment"===t.value&&!m&&a(s,{children:[p&&a(ge,{}),a(M,{customizations:e})]})]})}function Pe({identity:e}){return"businessCustomer"===e.current.value?$:_e}function we({onComplete:e}){const n=c(null),t=c(),[s,i]=r(!1),{environment:{services:{shopServer:d}},observability:u}=Y(),m=c(performance.now()),p=o(n=>{e(n),i(!0),t.current=n},[e]),b=o(({data:e,origin:t,source:a})=>{if("null"===t&&a===n.current?.contentWindow&&"string"==typeof e.payload&&""!==e.payload)switch(e.action){case"iovation_sandbox_error":u.leaveErrorBreadcrumb("[Iovation] Fingerprint error",{error:e.payload}),p("");break;case"iovation_sandbox_fingerprint":u.histogram({name:"iovation_fingerprint_load_time",value:performance.now()-m.current}),p(e.payload)}},[p,u]),v=o(()=>{n.current?.contentWindow&&n.current.contentWindow.postMessage({action:"iovation_sandbox_initialize"},"*")},[]);return l(()=>(window.addEventListener("message",b),()=>{window.removeEventListener("message",b)}),[b]),l(()=>{const e=setTimeout(()=>{void 0===t.current&&(u.histogram({name:"iovation_fingerprint_load_time",value:performance.now()-m.current}),p(""))},1e4);return()=>clearTimeout(e)},[p,u]),s?null:a(be,{ref:n,id:"iovation_sandbox_iframe",sandbox:"allow-scripts",src:new URL("/pay/iovation",d.url).href,style:{display:"none"},onLoad:v})}function Ie(){const[e,n]=r(!1),{i18n:t,checkout:{negotiator:s}}=Y(),{prequalifiedAnimatedBadgeShowCounter:i}=s.context,d=function(){const{userEvents:e,source:n,checkout:t,shop:a,shopPay:s,embed:i}=Y(),{prequalifiedAnimatedBadgeShowCounter:r}=t.negotiator.context;return o(()=>{r.value>0||e.monorailEvent({schemaId:"shopify_pay_payment_page_installments/1.4",payload:{...me(n,t,a,{embedPlatform:i?.platform,shopAppSurface:s.app.config.surface}),eventType:pe.PrequalifiedBadgeImpression,success:!0}})},[r,e,n,t,a,s,i])}(),u=t.translate("installments.installments_prequalified_status_badge"),m=function(e){const n=c(null),t=c(!1);return l(()=>{if(t.current)return;if(!window.IntersectionObserver)return t.current=!0,void e();const a=new IntersectionObserver(n=>{const i=n.some(({isIntersecting:e})=>e);s&&i&&(t.current=!0,a.unobserve(s),e())},{threshold:1}),s=n.current;return s&&a.observe(s),()=>{s&&a.unobserve(s)}},[e]),n}(o(()=>{n(!0),d(),i.value+=1},[i,d]));return a("div",{className:p("Pdl91",e&&"n7rut",i.value>1&&"_4PVkL"),ref:m,children:a("span",{className:"a3kZU",children:[a("span",{className:"F1g68",children:a(k,{type:"check-circle",size:"fill"})}),a("span",{className:"Wkh24",children:u})]})})}const Ae=b(function({title:e,subtitle:n,disabled:t,badge:s},i){const r=a(w,{color:t?"subdued":void 0,children:a(j,{type:"strong",children:e})}),l=a(w,{children:n});return s?a(S,{ref:i,gap:"small-100",children:[a(S,{direction:"inline",gap:"base",children:[r,a(Ie,{})]}),l]}):a(N,{ref:i,children:[r,l]})});function Le({ineligibilityReason:i}){const{observability:p,userEvents:b,i18n:v,source:h,checkout:f,shop:y,shopPay:_}=Y(),[S,P]=r(!1),w=O(),{recordRetailEvent:I}=de(),{negotiate:A}=T(),{paymentMethods:L}=f.negotiator.current.fields,j=ue(_),C=function(){const{checkout:{identity:e,negotiator:n},shopPay:a}=Y(),s=V(),i=n.current.fields.paymentMethods;return t(()=>{const n=s.value,t=a.user.installments.prequalifiedAmount.value,r=a.user.installments.credential.value,l=i.value?.find(e=>"wallet"===e.type&&"SHOPIFY_INSTALLMENTS"===e.name),o="shopPay"===e.current.value&&null!=n&&null!=l&&n.amount>=Math.max(l.minPrice.amount,50)&&n.currencyCode===l.minPrice.currencyCode,d=null!=t&&null!=n&&(!l?.cbtEnabled||t.currencyCode===n.currencyCode)&&(r?.requiresAdditionalInformation&&n.amount<=t.amount||!r?.requiresAdditionalInformation);return o&&d})}(),M=ce(),k=g(),{payNowLabel:H,payNowSubtitle:F,installmentsLabel:B,installmentsSubtitle:R}=M.value,q=_.user.installments.prequalifiedAmount.value,D=_.installments.isServiceAvailable.value,Z=_.session.paymentMethodOption.value,G=d(()=>Z?[Z.name]:[],[Z]),J=!D||f.installments.isUnavailable.value,Q=function({selectable:t}){const{userEvents:a,source:s,checkout:i,shop:r,shopPay:l,embed:d}=Y(),{ineligibilityReasons:p}=i.installments,{isServiceAvailable:b}=l.installments,{wasRejected:v}=l.user.installments,{isLoading:h}=l.session,f=n(null),y=c(!1),_=e(t);function g(){const e=_.value,n=e?void 0:JSON.stringify(function({ineligibilityReasons:e,serviceAvailable:n,userRejected:t}){return e.length>0?e:n?t?["user_rejected"]:["unknown"]:["installments_unavailable"]}({ineligibilityReasons:p.value,serviceAvailable:b.value,userRejected:v.value}));a.monorailEvent({schemaId:"shopify_pay_payment_page_installments/1.4",payload:{...me(s,i,r,{embedPlatform:d?.platform,shopAppSurface:l.app.config.surface}),eventType:pe.OptionImpression,success:e,errorMessage:n}})}return u(()=>{const e=f.value;if(!e||h.value||y.current)return;const n=()=>{y.current=!0,m(g)};if(!window.IntersectionObserver)return void n();const t=new IntersectionObserver(e=>{e.some(({isIntersecting:e})=>e)&&(t.disconnect(),n())},{threshold:1});return t.observe(e),()=>t.disconnect()}),o(e=>{f.value=e},[f])}({selectable:!J}),X=d(()=>{if(C.value&&q&&!J)return"prequalified"},[C.value,J,q]),$=o(async()=>{S||(P(!0),await A({force:!1,fieldsToResolve:["taxes","paymentMethods"],silenceViolations:z(["paymentLines"]),customizeNegotiation:e=>(e.payment?.paymentLines.push({amount:{any:!0},paymentMethod:{walletPaymentMethodConfig:{name:"SHOPIFY_INSTALLMENTS"}}}),e)}))},[A,S]);l(()=>{"SHOPIFY_INSTALLMENTS"===j&&$()},[$,j]);const ee=o(([e="SHOPIFY_INSTALLMENTS"])=>{const n=W(L.value)?.availableLoanTypes,{action:t,method:a}=function({paymentMethodName:e,availableLoanTypes:n}){if("SHOP_PAY"===e)return{action:"payment_method_pay_now",method:{type:"wallet",name:"SHOP_PAY"}};const t={type:"wallet",name:"SHOPIFY_INSTALLMENTS"};return K(n)?{action:"payment_method_interest_bearing_installments",method:t}:{action:"payment_method_installments",method:t}}({paymentMethodName:e,availableLoanTypes:n});_.session.unstable_updatePaymentMethodOption(a),"SHOP_PAY"===e&&_.installments.failedAttempt.value?.retryable&&_.installments.unstable_setFailedAttempt(null),w.value&&I(t),"SHOPIFY_INSTALLMENTS"===e&&p.log("payment_method_selected","[Installments] Payment method selected",{paymentMethodName:e}),b.monorailEvent({schemaId:"shopify_pay_payment_page_ui_interaction/1.2",payload:{...U(h,f,y),action:t}})},[L,_.session,_.installments,w,p,b,h,f,y,I]);return a(s,{children:[J&&a(N,{children:[a(E,{heading:k.translate("payment_ux.payment.payment_option.installments_unavailable"),tone:"info",children:i||k.translate("payment.payment_option.installments_temporarily_unavailable")}),a(x,{blockSize:"base"})]}),a(le.Provider,{value:!0,children:a(te,{presentation:"base",children:a(oe,{name:"payment_method_options",title:v.translate("payment.payment_option.accessibility_label"),titleHidden:!0,onChange:ee,values:G,children:[a(ne,{value:"SHOP_PAY",children:a(Ae,{title:H,subtitle:F})}),a(ne,{value:"SHOPIFY_INSTALLMENTS",disabled:J,children:[!J&&a(we,{onComplete:_.setDeviceFingerprint}),a(Ae,{ref:Q,title:B,subtitle:R,disabled:J,badge:X})]})]})})})]})}export{ve as P,Se as W,Le as a,Pe as g};