import{Et as e,Ft as t,It as n,Jt as a,Pt as s,Wt as i,Xt as l,Zt as r,en as o,ft as u,jt as c,nn as d,pt as p,vt as m,yt as v,zt as h}from"./630ba094.L_X-5TXi.js";import{AO as y,Ad as g,Bp as b,EA as f,Ed as _,Fd as P,Gb as S,Gg as I,Id as w,Mo as A,Nl as k,Od as C,RC as L,Vx as N,Xg as O,Xy as B,Yf as T,_p as M,al as E,eo as j,fy as x,gp as q,gw as F,hk as R,ho as z,io as H,jd as V,kp as Y,lk as D,nh as J,vl as W,vp as U,wv as X,xO as G}from"./6ec9a0fa.rdcQt2v8.js";import{o as K}from"./0f5b1987.BrdnjeT6.js";import{t as Z}from"./67e8c664.ByAbJtL3.js";import{i as Q,n as $,t as ee}from"./4618373b.CjXafxDy.js";import{i as te}from"./402b40d8.CQI88cKn.js";import{r as ne}from"./faece749.BI3CiyQ-.js";import{o as ae}from"./77d9e668.B6Nt2tia.js";import{V as se,d as ie,i as le,r as re,t as oe}from"./b2ef26e8.DM1tmxzK.js";import{X as ue,it as ce,nt as de,q as pe}from"./0e3247a0.Csj0q_SF.js";import{f as me,m as ve}from"./674595ba.CBCkPO6g.js";import{t as he}from"./542b75cf.C-_S3LI1.js";import{i as ye,r as ge}from"./b01c110b.h_AlXdR4.js";import{F as be,M as fe,N as _e,P as Pe}from"./4205169c.D52g_3ca.js";import{u as Se}from"./74e5a557.CRSHWf3c.js";import{t as Ie}from"./70565d02.Xm4DhHHO.js";import{t as we}from"./045c921f.CIVgwHWR.js";function Ae({selectorShowsTiles:e,afterPaymentSelector:n,renderVaultingAgreementInline:a}){const i=te(),l=z(),{checkout:r,i18n:o,shopPay:c,source:m}=G(),h=B(),y=g(),f=E(),{paymentMethods:_}=r.negotiator.current.fields,P=c.user.creditCards,S=u(me().creditCardDisabled),w=t(null),A=s(()=>!(h.value||L({checkout:r,source:m})?.pickupAddress)&&!y.value&&r.isShippingRequired.value),C=s(()=>function({identity:e},{billingPosition:t,vaultedSections:n,showBillingAddressInContext:a}){switch(e.current.value){case"shopPay":return"inContext"===t.value&&!n.value.payment;case"businessCustomer":return!0;default:return a.value}}({identity:r.identity},{billingPosition:l,vaultedSections:f,showBillingAddressInContext:A})),N=s(()=>ce(_.value)),O=s(()=>de({hasBogusGateway:N.value})),M=k(),j=s(()=>ve({checkout:r,shopPay:c})?null:function({identity:e,i18n:t},{paymentMethodMustSupportInterestBearingLoans:n,supportedCountryOptions:a,creditCards:s,creditCardDisabled:i}){if("shopPay"!==e.current.value)return null;if(!n)return null;if(!s.every(e=>i(e)))return null;const l=a.map(e=>e.label).join(", ");return l?t.translate("installments.installments_debit_cards_supported_countries",{countries:l}):t.translate("installments.installments_valid_debit_cards_fallback")}({identity:r.identity,i18n:M},{paymentMethodMustSupportInterestBearingLoans:r.installments.paymentMethodMustSupportInterestBearingLoans.value,supportedCountryOptions:r.installments.supportedCountryOptions.value,creditCards:P.value,creditCardDisabled:S.value})),x=v(pe,{blurValidationFieldDenylist:O.value,onSetFieldErrors:i,children:[v(ie,{vaultHandle:w}),v(I,{gap:"base",children:[v(ke,{}),v(le,{billingAddressInContext:C.value,vaultHandle:w,selectorShowsTiles:e,afterPaymentSelector:n,renderVaultingAgreementInline:a})]})]});return v(p,{when:j,fallback:x,children:e=>v(d,{children:[v(I,{gap:"small-400",children:[v(b,{level:2,children:o.translate("credit_card_form.add_debit_card")}),v(T,{color:"subdued",children:e})]}),x]})})}function ke(){return re(),null}var Ce="shipping_address",Le="custom_billing_address";function Ne({renderFormOnly:e=!1}={}){const{i18n:t,checkout:{negotiator:n}}=G(),a=C(),{billingAddressOption:o}=n.parts,u=P(),c="shipping"===o.value?Ce:Le,[d,m]=r([c]),h=ye(),g=s(()=>h.value.isBilling),b=v(p,{when:g,children:v(ge,{})});i(()=>{m([c])},[c]);const f=l(e=>{const t="shipping_address"===e[0]?"shipping":"custom";o.value=t,m(e),"shipping"===t&&u()},[o,u]);w();const _=l(({billing:e})=>{e.value=!0},[]),S=l(({billing:e})=>{e.value=!1},[]);return v(p,{when:()=>!e&&"form"!==a.value,fallback:v(K,{onValid:_,onInvalid:S,children:v(se,{children:b})}),children:v($,{name:"billing_address_selector",values:d,onChange:f,variant:"block",children:[v(ee,{value:Ce,accessibilityLabel:t.translate("payment.same_billing_address_label"),children:v(y,{type:"strong",children:t.translate("payment.same_billing_address_label")})}),v(ee,{value:Le,selectedContent:v(K,{onValid:_,onInvalid:S,children:v(se,{children:b})}),accessibilityLabel:t.translate("payment.different_billing_address_label"),children:v(y,{type:"strong",children:t.translate("payment.different_billing_address_label")})})]})})}var Oe=()=>{const{i18n:e,checkout:{identity:t}}=G(),n=Te({identity:t});return v(I,{accessibilityRole:"group",accessibilityLabelledBy:"billingAddress",gap:"base",children:[v(b,{id:"billingAddress",level:2,children:e.translate("payment.billing_address_title")}),v(n,{})]})};function Be({dynamicPaymentExtensions:e=[],children:t}){V();const n=z(),a=g(),{checkout:i}=G(),l=E(),r=s(()=>W({checkout:i})),u=l.value.payment&&l.value.billing&&!r.value,[c]=ue(),p=o(()=>Object.values(F).some(e=>c===e),[c]),m=!u&&!a.value&&!p;return v(I,{gap:"base",children:["beforePayment"===n.value&&m&&v(Oe,{}),t,"afterPayment"===n.value&&!p&&v(d,{children:[m&&v(Oe,{}),v(Y,{customizations:e})]})]})}function Te({identity:e}){return"businessCustomer"===e.current.value?oe:Ne}var Me={zeroInterest:"zero_interest",zeroPercentApr:"zero_percent_apr"},Ee={prequalified:"prequalified",...Me};function je({variant:e,interestBadge:t,prequalified:n}){const a=n?"prequalified":void 0;switch(e){case"treatment_interest_first":return t??a;case"control":case null:return a}}function xe({onComplete:e}){const n=a(null),s=a(),r=t(!1),{environment:{services:{shopServer:o}},observability:u}=G(),c=a(performance.now()),d=l(t=>{e(t),r.value=!0,s.current=t},[e,r]),p=l(({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}),d("");break;case"iovation_sandbox_fingerprint":u.histogram({name:"iovation_fingerprint_load_time",value:performance.now()-c.current}),d(e.payload)}},[d,u]),m=l(()=>{n.current?.contentWindow&&n.current.contentWindow.postMessage({action:"iovation_sandbox_initialize"},"*")},[]);return i(()=>(window.addEventListener("message",p),()=>{window.removeEventListener("message",p)}),[p]),i(()=>{const e=setTimeout(()=>{void 0===s.current&&(u.histogram({name:"iovation_fingerprint_load_time",value:performance.now()-c.current}),d(""))},1e4);return()=>clearTimeout(e)},[d,u]),r.value?null:v(Z,{ref:n,id:"iovation_sandbox_iframe",sandbox:"allow-scripts",src:new URL("/pay/iovation",o.url).href,style:{display:"none"},onLoad:m})}function qe(e){const t=a(null),n=a(!1);return i(()=>{if(n.current)return;if(!window.IntersectionObserver)return n.current=!0,void e();const a=new IntersectionObserver(t=>{const i=t.some(({isIntersecting:e})=>e);s&&i&&(n.current=!0,a.unobserve(s),e())},{threshold:1}),s=t.current;return s&&a.observe(s),()=>{s&&a.unobserve(s)}},[e]),t}var Fe=j.Purple.L5.toRgb(),Re=j.Purple.P40.toRgb();function ze({kind:e}){const{i18n:t}=G(),n=function(){const{userEvents:e,source:t,checkout:n,shop:a,shopPay:s,client:i}=G();return l(l=>{const r=n.negotiator.context.interestBadgeImpressionsSignal;r.value.includes(l)||(r.value=[...r.value,l],e.monorailEvent({schemaId:"shopify_pay_payment_page_installments/1.4",payload:{...Se(t,n,a,i.userAgentDetails),eventType:A.InterestBadgeImpression,success:!0,metadata:JSON.stringify({badge_type:Me[l],variant:s.installments.spiCheckoutBadgingVariant.value})}}))},[e,t,n,a,s,i])}(),a=qe(l(()=>n(e),[e,n])),s="zeroPercentApr"===e?t.translate("installments.installments_zero_percent_apr_badge"):t.translate("installments.installments_zero_interest_badge");return v("div",{ref:a,style:m({[R.color.default.badgeBackground]:Fe,[R.color.default.badgeText]:Re}),children:v(U,{icon:"discount",size:"small",children:s})})}function He(){const e=t(!1),{i18n:n,checkout:{negotiator:a}}=G(),{prequalifiedAnimatedBadgeShowCounter:s}=a.context,i=function(){const{userEvents:e,source:t,checkout:n,shop:a,shopPay:s,client:i}=G(),{prequalifiedAnimatedBadgeShowCounter:r}=n.negotiator.context;return l(()=>{if(r.value>0)return;const l=s.installments.spiCheckoutBadgingVariant.value;e.monorailEvent({schemaId:"shopify_pay_payment_page_installments/1.4",payload:{...Se(t,n,a,i.userAgentDetails),eventType:A.PrequalifiedBadgeImpression,success:!0,...l?{metadata:JSON.stringify({variant:l})}:{}}})},[r,e,t,n,a,s,i])}(),r=n.translate("installments.installments_prequalified_status_badge"),o=qe(l(()=>{e.value=!0,i(),s.value+=1},[e,s,i]));return v("div",{className:c("Pdl91",e.value&&"n7rut",s.value>1&&"_4PVkL"),ref:o,children:v("span",{className:"a3kZU",children:[v("span",{className:"F1g68",children:v(D,{type:"check-circle",size:"fill"})}),v("span",{className:"Wkh24",children:r})]})})}var Ve=e(function({title:e,subtitle:t,disabled:n,badge:a},s){const i=v(T,{color:n?"subdued":void 0,children:v(y,{type:"strong",children:e})}),l=v(T,{children:t});return v(p,{when:()=>a?.value,fallback:v(O,{ref:s,children:[i,l]}),children:e=>v(I,"prequalified"===e?{ref:s,gap:"small-100",children:[v(I,{direction:"inline",gap:"base",children:[i,v(He,{})]}),l]}:{ref:s,gap:"small-400",children:[v(O,{children:[i,l]}),v(ze,{kind:e},e)]})})});function Ye({ineligibilityReason:e}){const{observability:o,userEvents:c,i18n:m,source:y,checkout:{negotiator:g,installments:b,configuration:P},shop:I,shopPay:w}=G(),[C,L]=r(!1),B=J(),{recordRetailEvent:T}=be(),{paymentMethods:E}=g.current.fields,j=s(()=>he(w)).value,F=Ie(),R=k(),z=s(()=>F.value.payNowLabel),V=s(()=>F.value.payNowSubtitle),Y=s(()=>F.value.installmentsLabel),D=s(()=>F.value.installmentsSubtitle),W=s(()=>F.value.termsCase),U=s(()=>e?.value||R.translate("payment.payment_option.installments_temporarily_unavailable")),K=s(()=>w.session.paymentMethodOption.value?.name),Z=s(()=>K.value?[K.value]:[]),$=s(()=>!w.installments.isServiceAvailable.value||b.isUnavailable.value),te=function({selectable:e}){const{observability:s,userEvents:i,source:r,checkout:o,shop:c,shopPay:d,client:p}=G(),{ineligibilityReasons:m,hasFinancingPlans:v,config:y}=o.installments,{isServiceAvailable:g}=d.installments,{wasRejected:b}=d.user.installments,{isLoading:f}=d.session,_=t(null),P=a(!1),S=u(e);function I(){const e=S.value,t=e?void 0:function({ineligibilityReasons:e,serviceAvailable:t,userRejected:n}){return e.length>0?e:t?n?["user_rejected"]:["unknown"]:["installments_unavailable"]}({ineligibilityReasons:m.value,serviceAvailable:g.value,userRejected:b.value});s.counter({name:"shop_pay_installments_option_impression",value:1,attributes:{selectable:e}}),s.log("installments_option_impression","[Installments] Payment option impression",{selectable:e,disabledReasons:t}),i.monorailEvent({schemaId:"shopify_pay_payment_page_installments/1.4",payload:{...Se(r,o,c,p.userAgentDetails),eventType:A.OptionImpression,success:e,errorMessage:t&&JSON.stringify(t),metadata:JSON.stringify({financing_plans_loaded:v.value,available_loan_types:y.value?.availableLoanTypes??[]})}})}return n(()=>{const e=_.value;if(!e||f.value||P.current)return;const t=()=>{P.current=!0,h(I)};if(!window.IntersectionObserver)return void t();const n=new IntersectionObserver(e=>{e.some(({isIntersecting:e})=>e)&&(n.disconnect(),t())},{threshold:1});return n.observe(e),()=>n.disconnect()}),l(e=>{_.value=e},[_])}({selectable:!$.value}),se=function({termsCase:e,installmentsNotAvailable:t}){const{shopPay:n}=G(),a=function(){const{checkout:{identity:e,negotiator:t},shopPay:n}=G(),a=X(),i=t.current.fields.paymentMethods;return s(()=>{const t=a.value,s=n.user.installments.prequalifiedAmount.value,l=n.user.installments.credential.value,r=i.value?.find(e=>"wallet"===e.type&&"SHOPIFY_INSTALLMENTS"===e.name),o="shopPay"===e.current.value&&null!=t&&null!=r&&t.amount>=Math.max(r.minPrice.amount,50)&&t.currencyCode===r.minPrice.currencyCode,u=null!=s&&null!=t&&(!r?.cbtEnabled||s.currencyCode===t.currencyCode)&&(l?.requiresAdditionalInformation&&t.amount<=s.amount||!l?.requiresAdditionalInformation);return o&&u})}(),i=we(e),l=s(()=>{if(t.value)return{badge:void 0,interestBadge:void 0,prequalified:!1};const e=Boolean(a.value&&n.user.installments.prequalifiedAmount.value),s=n.installments.spiCheckoutBadgingVariant.value,l=i.value;return{badge:je({variant:s,interestBadge:l,prequalified:e}),interestBadge:l,prequalified:e}}),r=s(()=>void 0!==l.value.interestBadge),o=s(()=>l.value.badge);return _e({experiment:fe,storageKey:N.SpiCheckoutBadgingExposure,exposed:r}),function({choice:e,hasInterestBadge:t}){const{observability:n,userEvents:a,source:i,checkout:l,shop:r,shopPay:o,client:c}=G(),d=f(),p=u(!d),m=s(()=>t.value&&p.value);Pe({storageKey:N.SpiBadgeDecision,when:m,run:()=>{const{interestBadge:t,prequalified:s,badge:u}=e.value;if(!t)return;const d=o.installments.spiCheckoutBadgingVariant.value,p=u?Ee[u]:"none";n.counter({name:"shop_pay_installments_badge_decision",value:1,attributes:{variant:d,badge_shown:p,prequalified:s,surface:"selector"}}),a.monorailEvent({schemaId:"shopify_pay_payment_page_installments/1.4",payload:{...Se(i,l,r,c.userAgentDetails),eventType:A.BadgeDecision,success:!0,metadata:JSON.stringify({variant:d,interest_badge:Me[t],prequalified:s,badge_shown:p,surface:"selector"})}})}})}({choice:l,hasInterestBadge:r}),o}({termsCase:W,installmentsNotAvailable:$}),ie=l(async()=>{C||(L(!0),await g.negotiate({withResultHandling:!0,force:!1,fieldsToResolve:["taxes","paymentMethods"],silenceViolations:x(["paymentLines"]),customizeNegotiation:e=>(e.payment?.paymentLines.push({amount:{any:!0},paymentMethod:{walletPaymentMethodConfig:{name:"SHOPIFY_INSTALLMENTS"}}}),e)}))},[g,C]);i(()=>{"SHOPIFY_INSTALLMENTS"===j&&ie()},[ie,j]);const le=l(([e="SHOPIFY_INSTALLMENTS"])=>{const t=S(E.value)?.availableLoanTypes,{action:n,method:a}=function({paymentMethodName:e,availableLoanTypes:t}){if("SHOP_PAY"===e)return{action:"payment_method_pay_now",method:{type:"wallet",name:"SHOP_PAY"}};const n={type:"wallet",name:"SHOPIFY_INSTALLMENTS"};return H(t)?{action:"payment_method_interest_bearing_installments",method:n}:{action:"payment_method_installments",method:n}}({paymentMethodName:e,availableLoanTypes:t});w.session.selectPaymentMethodOption(a),"SHOP_PAY"===e&&w.installments.failedAttempt.value?.retryable&&w.installments.unstable_setFailedAttempt(null),B.value&&T(n),"SHOPIFY_INSTALLMENTS"===e&&(o.counter({name:"shop_pay_installments_option_selected",value:1,attributes:{action:n}}),o.log("payment_method_selected","[Installments] Payment method selected",{paymentMethodName:e})),c.monorailEvent({schemaId:"shopify_pay_payment_page_ui_interaction/1.2",payload:{..._(y,{configuration:P},I),action:n}})},[E,w.session,w.installments,B,o,c,y,P,I,T]);return v(d,{children:[v(p,{when:$,children:v(O,{children:[v(q,{heading:R.translate("payment_ux.payment.payment_option.installments_unavailable"),tone:"info",children:U}),v(M,{blockSize:"base"})]})}),v(ne.Provider,{value:!0,children:v(Q,{presentation:"base",children:v(ae,{name:"payment_method_options",title:m.translate("payment.payment_option.accessibility_label"),titleHidden:!0,onChange:le,values:Z.value,children:[v(ee,{value:"SHOP_PAY",children:v(Ve,{title:z,subtitle:V})}),v(ee,{value:"SHOPIFY_INSTALLMENTS",disabled:$.value,children:[!$.value&&v(xe,{onComplete:w.setDeviceFingerprint}),v(Ve,{ref:te,title:Y,subtitle:D,disabled:$.value,badge:se})]})]})})})]})}export{Ae as i,Be as n,Te as r,Ye as t};