1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["PostPurchaseShouldRender.saKm79LF.js","esnext-vendor.BDPAaZdq.js","hooks-useReplaceShopPayInHistory.C8UL-mAH.js","app.D1P6yWfp.js","assets/app.BuSMBobh.css","assets/useReplaceShopPayInHistory.BpuyvRSB.css","extensions-rpc.Sg1wfpr_.js","amazon-pay-useAmazonPayPaymentLine.BXwZMsYY.js","performance-index.mu6MOGR9.js","shared-permissions.BaDWlj5_.js","hooks-usePostPurchase.BPY08f0g.js","hydrate.B0xlt2dG.js","helpers-getNormalizedPaymentMethodName.B-mE5wnL.js","hooks-useShopPayExternalAppContext.DyGXtar4.js","assets/previous.SPd9u6sV.css","component-Tips.BiqWkIZ0.js","Choice.BIzIW4rp.js","Checkbox.CiixBh9Z.js","assets/Checkbox.SrYMuQu4.css","assets/Choice.B7lVAtpz.css","NumberField.BZROjWxa.js","assets/NumberField.CRpcZnVJ.css","Section._KuAKpGQ.js","assets/Section.CU18S7Ap.css","assets/Tips.D3S9_XMm.css","component-MsiInstallmentsSelect.Di8KHei5.js","PaymentIcon.CQXs-ePm.js","assets/PaymentIcon.gzvCNwz_.css","PaymentLine.BkPc0Zsc.js","assets/PaymentLine.BGhbZYQP.css","EmptyState.b83C9ddY.js","localization-index.Bo8bPuxq.js","helpers-credit-card-disabled.BnSr1GsQ.js","assets/index.CIy8uDiZ.css","assets/EmptyState.BEvzDDvy.css","hooks-useUpdateCheckoutAddress.xu8w67CI.js","helpers-derivations.DLW2fhKL.js","graphql-PaymentSessionMutation.BhOnX3QJ.js","money-toShopPayMoneyInput.-nuohgDW.js","redemption-promotions.CgqGtCd-.js","shop-pay-normalizeBuyerDetails.ThnUnxcv.js","checkout-updaters-helpers.BAeH3ddd.js","helpers-setAddressErrors.BA8OjimY.js"])))=>i.map(i=>d[i]); 2import{_ as nt,S as Gt}from"./app.D1P6yWfp.js";import{d as rt,u as m,f as B,S as Yt,i as Oe,h as U,a as it,k as X,q as E,y as N,E as I,ag as Aa,n as Ea,T as ae,x as qt,A as ce,o as zt,e as ka,G as wa,r as Ia,_ as La,X as Na,af as Da}from"./esnext-vendor.BDPAaZdq.js";import{H as Je,b as ve,al as qe,B as ke,a3 as ot,aB as xa,K as Ta,bJ as Ht,L as Wt,fI as Ra,O as Ba,fD as Fa,I as dt,c as te,P as Ua,h4 as Va,aa as bt,g9 as Qt,h5 as lt,cn as Oa,h6 as Pt,A as $a,h as ct,a0 as Ka,fW as Ga,U as Ya,h7 as qa,h8 as za,W as jt,E as Xt,h9 as Ha,F as ze,bv as Jt,o as ne,aw as Wa,d3 as Qa,bd as ja,aJ as Xa,a as Zt,S as Ja,bG as Za,eU as es,bo as ts,bp as as,bq as ss,ha as ns,hb as ut,hc as gt,hd as rs,he as _t,hf as St,hg as Mt,hh as is}from"./hydrate.B0xlt2dG.js";import{O as L,P as Y,Q as se,a5 as ea,cD as os,dv as ds,ga as ye,g6 as ls,k as H,hs as cs,ht as He,bJ as us,hu as ms,br as hs,hv as ps,hw as ys,b$ as fe,cC as fs,hx as Cs,bA as vs,aq as ta,f$ as bs,X as aa,m as Ps,hy as gs,l as be,fW as _s,q as we,T as sa,aS as $e,aQ as ge,gT as mt,hz as na,a3 as ht,G as Fe,du as Ss,eG as Ms,hA as As,U as W,hB as De,hC as Es,V as Pe,hD as ks,hE as At,hF as ws,hG as Is,hH as Ls,bY as Ns,a7 as ra,cc as Ds,bo as Ke,hI as xs,hJ as Ts,aY as Rs,hK as pt,hL as Bs,hM as ia,aW as oa,v as Fs,hN as Us,hO as da,hP as Vs,hQ as Os,hR as $s,cf as Ks,cg as la,bp as Gs,ae as Ys,aL as qs,hS as zs,u as Hs}from"./hooks-useReplaceShopPayInHistory.C8UL-mAH.js";import{u as Ws}from"./amazon-pay-useAmazonPayPaymentLine.BXwZMsYY.js";import{P as ca}from"./PaymentIcon.CQXs-ePm.js";import{a as Qs}from"./PaymentLine.BkPc0Zsc.js";import{b as Et,E as js}from"./EmptyState.b83C9ddY.js";import{a as Xs,c as Js,b as Zs,u as en}from"./hooks-useUpdateCheckoutAddress.xu8w67CI.js";import{S as tn,u as an}from"./money-toShopPayMoneyInput.-nuohgDW.js";import{s as sn,n as nn}from"./shop-pay-normalizeBuyerDetails.ThnUnxcv.js";import{a as rn,i as on,e as dn,d as ln}from"./localization-index.Bo8bPuxq.js";import{s as cn}from"./helpers-setAddressErrors.BA8OjimY.js";import{a as ua,b as Ze}from"./Choice.BIzIW4rp.js";import{A as un,a as mn}from"./graphql-PaymentSessionMutation.BhOnX3QJ.js";const ai=rt({displayName:"PostPurchaseShouldRender",suspense:!1,load:()=>nt(()=>import("./PostPurchaseShouldRender.saKm79LF.js").then(t=>t.P),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]))});function hn({renderInSection:t,hideHeading:e,headingLevel:a=2}){const{i18n:s,shop:{name:n,showTipPayments:r}}=L(),{tipLines:o}=Y(),{tipLines:l}=se(),i=B(()=>{const u=o.value?.[0]??l.value[0];return r||!!(u&&u.amount.amount>0)}),d=s.translate("tips.description",{shop_name:n}),c=m(ke,{paddingBlockEnd:"base",children:[!e&&m(Yt,{children:[m(Je,{level:a,children:s.translate("tips.title")}),m(ve,{blockSize:"base"})]}),m(qe,{contentDisplay:"block",inlineSize:"100%",children:d}),m(Oe,{when:i,children:[m(ve,{blockSize:"small-200"}),m(qe,{contentDisplay:"block",inlineSize:"100%",children:s.translate("tips.custom_label")}),m(ve,{blockSize:"small-100"}),m(qe,{contentDisplay:"block",inlineSize:"33%",children:s.translate("tips.add_tip")})]})]});return t?m(ot,{accessibilityLabel:s.translate("tips.title"),children:c}):c}function pn(t){const{observability:e}=L();U(()=>{t&&e.error(t,{metadata:{tips:{component:"Tips",failure:"lazy_load"}}})},[t,e])}const si=rt({displayName:"Tips",renderLoading:t=>m(hn,{...t}),useError:pn,load:()=>nt(()=>import("./component-Tips.BiqWkIZ0.js"),__vite__mapDeps([15,1,11,2,3,4,5,12,9,13,14,16,17,18,19,20,21,22,23,24]))}),yn=Ba("AmazonPayChangePaymentLinkButton");function ni(){const{i18n:t,observability:e}=L(),{inMemoryAmazonPayParts:{sdkStatus:a}}=ea(),s=B(()=>{const i=a.value;return i.status===xa.Available?i.sdk:void 0}),n=Ws(),r=Ta(void 0,yn),{hasError:o}=Ht(os),l=t.translate("vaulted.change_button");return n.value?m(Oe,{when:s,children:i=>m(Wt,{onClick:()=>{try{const{checkout_session_id:c}=Ra(n.value.method.walletParams);i.Pay.changePaymentMethod({amazonCheckoutSessionId:c,isDeclined:o})}catch(c){e.error(new fn(`Error on changing buyer payment method. Details: ${c}`,{cause:c}))}},id:r,children:l})}):null}
2class fn extends Error{constructor(){super(...arguments),this.name="AmazonPayChangePaymentLinkError"}}const Cn=new Map([["american_express","american_express"],["amex","amex"],["bogus","bogus"],["cartes_bancaires","cartes_bancaires"],["dankort","dankort"],["diners_club","diners_club"],["discover","discover"],["elo","elo"],["forbrugsforeningen","forbrugsforeningen"],["hypercard","hypercard"],["interac","interac"],["jcb","jcb"],["laser","laser"],["maestro","maestro"],["mastercard","mastercard"],["rupay","rupay"],["unionpay","unionpay"],["visa","visa"],["visaelectron","visaelectron"]]);function ri({brand:t,descriptor:e}){const{hasError:a}=Fa(),s=t?.toLowerCase().replace(/\s+/g,"_")??"",n=Cn.get(s)??"generic";return m(te,{direction:"inline",children:[a&&m(Yt,{children:[m(dt,{tone:"critical",type:"alert-circle"}),m(ve,{display:"inline",inlineSize:"small-400"})]}),m(Qs,{icon:m(ca,{type:n}),details:e})]})}function vn(){const{i18n:t}=L(),e=se().purchaseOrderNumber.value;if(!e)return null;const a=`${t.translate("payment.purchase_order_number.title")} #${e}`;return m(Ua,{children:a})}const bn=t=>m("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"66 -30 151 80",...t,children:[m("path",{fill:"inherit",stroke:"inherit",strokeWidth:2,d:"M73.8-18.2c-4.4.8-7.3 4.9-6.5 9.3l7.6 43.3c.8 4.3 4.9 7.3 9.3 6.5l59.7-10.5c3.3-.6 7.4-3.3 9.1-6.1l14.4-22.5c2.4-3.7 1.5-8.9-2-11.6L144.2-26c-2.6-2-7.4-3.2-10.7-2.6 0-.1-59.7 10.4-59.7 10.4z"}),m("circle",{cx:157.2,cy:-2.9,r:3.5,fill:"inherit",stroke:"inherit",strokeWidth:2}),m("path",{fill:"inherit",stroke:"inherit",strokeWidth:2,d:"m95.9 9.1 11.5 7.4 18-24.5m31.8 5.1c23.3-7.1 31.6 22.2 57.5-13.1"})]}),Pn="agRve",gn="FiV0Z",kt={NoPaymentRequiredWrapper:Pn,FreeTagIcon:gn};function ii({minimal:t,reason:e,vaulted:a}){const{i18n:s}=L(),r=Va().value.length,o=l=>{switch(l){case"giftCard":return s.translate("payment.order_covered_by_gift_cards_notice",{count:r});case"freeOrder":return s.translate("payment.free_order_notice_html");case"storeCredit":return s.translate("payment.order_covered_by_store_credit_notice");case"redeemables":return s.translate("payment.order_covered_by_redeemables_notice");case"deferred":return s.translate("payment_gateway.deferred_payment_label");default:it(l)}};return a?m(te,{gap:"base",children:[m(bt,{children:o(e)}),m(vn,{})]}):t?m(js,{children:m(Et,{children:o(e)})}):m("div",{className:kt.NoPaymentRequiredWrapper,children:m(te,{gap:"large-200",alignItems:"center",children:[m(bn,{className:kt.FreeTagIcon,focusable:"false","aria-hidden":"true"}),m(Et,{children:m(bt,{children:o(e)})})]})})}class _n extends Gt{constructor(){super(...arguments),this.name="AmazonPayMissingPaymentPreferencesError"}}function oi(){const t=se().paymentLines;return B(()=>{const e=t.value,a=(()=>{const[n]=e.filter(i=>i.method.type==="walletsPlatformPaymentMethod");if(!n)return"";const o=n.method.walletParams.payment_preferences?.[0];if(!o)throw new _n("Amazon Pay wallet params missing payment preferences",{groupingHash:"AmazonPay::usePaymentDetails::AmazonPayMissingPaymentPreferencesError"});return o.paymentDescriptor.replace("****","â¢â¢â¢â¢ ").replace(/(\((.*?)\))/,"").trim()})();return{brand:(()=>{if(!a)return;const n=a.match(/^(.+?)\s+â¢â¢â¢â¢/);if(!n)return a;const r=n[1];return r===void 0?a:r.trim()})(),descriptor:a}})}const wt={id:"2bcff8985dbaa04eadb413f088e89a17952466f58df58d4f1fd47003417e8f71",type:"query",name:"CreditCardActiveSubscriptions",source:"query CreditCardActiveSubscriptions($id:ID!,$uuid:String!,$first:Int){creditCardActiveSubscriptions(id:$id,uuid:$uuid,first:$first){pageInfo{hasNextPage __typename}nodes __typename}}"},Be=Object.freeze({name:null,number:null,verification_value:null,expiry:null,issue_date:null,issue_number:null});var ma=(t=>(t.FirstName="firstName",t.LastName="lastName",t.Number="number",t.Cvv="verificationValue",t.Month="month",t.Year="year",t.Base="base",t.DebitOnly="debitOnly",t))(ma||{});
2const It={baseMessage:null,fieldErrors:Be,blockedByDuplicateAutopayCard:!1};function di(){const{i18n:t,observability:e}=L(),[a,s]=X(It),n=E((d,c)=>{e.counter({name:d,value:1,attributes:{errorField:c.field.join("-"),errorMessage:c.message}})},[e]),r=E(d=>{if(!d||!d.length){s({baseMessage:t.translate("credit_card_form.generic_card_error"),fieldErrors:Be,blockedByDuplicateAutopayCard:!1});return}const c={...Be};let u=null;d.forEach(p=>{switch(n("save_credit_card_error",p),p.field?.[1]){case"firstName":c.name=t.translate("field_errors.credit_card_name_billing_invalid");return;case"lastName":c.name=t.translate("field_errors.credit_card_name_invalid");return;case"month":case"year":c.expiry=t.translate("field_errors.credit_card_expiry_invalid");return;case"number":c.number=t.translate("field_errors.credit_card_number_invalid");return;case"verificationValue":c.verification_value=t.translate("payment.card_fields.errors.invalid.verification_value");return;case"debitOnly":u=t.translate("payment_errors.debit_only");return;case"base":if(p.message==="credit_card_is_expired"){c.expiry=t.translate("payment_errors.card_has_expired");return}else if(p.message==="failed_to_verify_credit_card"){u=t.translate("payment.generic_incorrect_card_info");return}else if(p.message==="three_d_secure_authentication_failed"){u=t.translate("payment_errors.three_d_secure_failed_payment_method");return}else if(p.message==="billing_address_missing"){u=t.translate("payment_errors.payment_method_billing_address");return}}if(p.message==="too_many_credit_cards"){u=t.translate("credit_card_form.max_cards_reached",{max_cards:ds});return}u=t.translate("credit_card_form.generic_card_error"),n("save_credit_card_error_unhandled",p)}
2),s({baseMessage:u,fieldErrors:c,blockedByDuplicateAutopayCard:!1})},[t,n]),o=E(()=>{e.counter({name:"save_credit_card_blocked_by_autopay",value:1}),s({baseMessage:null,fieldErrors:Be,blockedByDuplicateAutopayCard:!0})},[e]),l=E(()=>{s(It)},[]),i=E(d=>{e.counter({name:"save_credit_card_vaulting_failure",value:1,attributes:{reason:d}}),r(d==="missing_billing_address"?[{field:["creditCard","base"],message:"billing_address_missing"}]:void 0)},[e,r]);return{creditCardErrors:a,setCreditCardErrors:r,clearCreditCardErrors:l,failCardVaulting:i,blockDuplicateAutopayCard:o}}function G(t){return t?.paymentMethod==="CREDIT_CARD"}function li(t){return t.paymentMethod==="IDEAL"||t.paymentMethod==="CUSTOM_ONSITE"&&t.paymentBrands?.some(e=>e.toLowerCase()==="ideal")===!0}function ci(t){return t.paymentMethod==="APPLE_PAY"}function ui(t){return t.paymentMethod==="CUSTOM_ONSITE"}function mi(t){return t.paymentMethod==="SHOP_PAY"}function hi(t){return t.paymentMethod==="SHOP_PAY_INSTALLMENTS"}function pi(t){return t.paymentMethod==="PAYPAL"}function yi(t){return t.paymentMethod==="BANK"}function et(t){return t.paymentMethod==="DEFERRED"}function fi(t){return t.paymentMethod==="OFFSITE"||t.paymentMethod==="MANUAL_PAYMENT"||t.paymentMethod==="CUSTOM_MANUAL_PAYMENT"||t.paymentMethod==="PAYMENT_ON_DELIVERY"}function Sn(t){return G(t)||!!t.lastUsedAt}function Mn(t){for(const e of t)if(!G(e)||!e.paymentAttributes.expired)return e;return t[0]}function An({selected:t,paymentMethods:e,availablePaymentMethods:a}){return!!(ye(t,a)||G(t)&&e.some(({method:s})=>s.paymentMethod===t.paymentMethod&&s.id===t.id))}function En(t,e){let a=t.paymentMethod.toLowerCase(),s="";switch(t.paymentMethod){case"CREDIT_CARD":t.paymentAttributes?.brand&&(a=t.paymentAttributes.brand);break;case"CUSTOM_ONSITE":{a=ls(e,{paymentBrands:t.paymentBrands,paymentMethodIdentifier:t.paymentMethodIdentifier})?.name||"custom_onsite",s=t.paymentBrands?.slice().sort().join(",")??"";break}case"IDEAL":a="ideal";break;case"OFFSITE":a=t.name,s=t.paymentBrands?.slice().sort().join(",")??"";break;case"MANUAL_PAYMENT":case"CUSTOM_MANUAL_PAYMENT":case"PAYMENT_ON_DELIVERY":a=t.name;break;case"APPLE_PAY":a="apple_pay";break;case"SHOP_PAY":a="shop_pay";break;case"SHOP_PAY_INSTALLMENTS":a="shopify_installments";break;case"PAYPAL":a="paypal_express";break;case"BANK":a=t.displayName||"bank";break;case"DEFERRED":a="deferred";break;default:it(t)}return{paymentMethodName:a,paymentBrands:s}}const re={markBuyerHasActed:!1,updateSelectedCardBin:!1,selectedCardFirstDigits:void 0,preserveExistingBinPrefix:!1,claimMsiBin:!1,claimedMsiBin:void 0,shouldNegotiate:!1};function ha(t){return{id:t.id,bank:t.bank,brand:t.brand,defaultPaymentMethod:t.preferred,expired:t.expired,expiryMonth:t.expiryMonth,expiryYear:t.expiryYear,lastDigits:t.lastDigits,lastUsedAt:t.lastUsedAt,name:t.name,nickname:t.nickname,billingAddress:t.billingAddress,cvvVerification:t.verified?void 0:{type:"session-token"}}}function xe(t){switch(t.paymentMethod){case"CREDIT_CARD":return{id:t.id,paymentMethod:"CREDIT_CARD",paymentAttributes:ha(t.paymentAttributes),lastUsedAt:t.lastUsedAt};case"IDEAL":return t;case"CUSTOM_ONSITE":return t;case"APPLE_PAY":return t;case"OFFSITE":return t;case"MANUAL_PAYMENT":return t;case"CUSTOM_MANUAL_PAYMENT":return t;case"PAYMENT_ON_DELIVERY":return t}}function tt(t,e){switch(t.paymentMethod){case"CREDIT_CARD":return e.find(a=>H(a)&&a.id===t.id);case"IDEAL":return t;case"CUSTOM_ONSITE":return t;case"APPLE_PAY":return t;case"OFFSITE":return t;case"MANUAL_PAYMENT":return t;case"CUSTOM_MANUAL_PAYMENT":return t;case"PAYMENT_ON_DELIVERY":return t;case"SHOP_PAY":case"SHOP_PAY_INSTALLMENTS":case"PAYPAL":case"BANK":case"DEFERRED":return;default:it(t)}}class kn extends Error{constructor(){super(...arguments),this.name="EmptySessionIdError"}}
2class wn extends Error{constructor(){super(...arguments),this.name="BuyerDetailsRefreshError"}}const In="credit_card_not_found";function Ln(t){return t.errors?.some(({message:e})=>e===In)??!1}class Nn{constructor(e){this.newCard=N(void 0),this.canSetCreditCardNickname=N(!0),this.addCreditCardStrategy="vault-and-select",this.deps=e;const{shopPay:a,installmentsPaymentMethodSelected:s,isApplePayAvailable:n,filteredNegotiatedPaymentMethods:r,isCreditCardDisabled:o,msiEligibilityByCardId:l,hasSellingPlan:i}=e;this.availablePaymentMethods=N(r),this.shopPayAvailableUserStoredPaymentMethods=I(()=>{const c=this.availablePaymentMethods.value;return c.length?Ps(a.user.paymentMethods.value,c):[]}),this.availableUserStoredPaymentMethods=I(()=>this.shopPayAvailableUserStoredPaymentMethods.value.map(xe)),this.promotedMethods=I(()=>a.session.promotedPaymentMethods.value.map(xe)),this.selectedPaymentMethod=I(()=>{const c=a.session.selectedPaymentMethod.value;return c?xe(c):void 0}),this.selectedCreditCard=I(()=>{const c=a.session.selectedPaymentMethod.value;return c&&H(c)?ha(c.paymentAttributes):void 0}),this.shopPayPaymentMethods=I(()=>{const c=a.user.paymentMethods.value,u=this.shopPayAvailableUserStoredPaymentMethods.value,p=this.availablePaymentMethods.value,h=a.session.promotedPaymentMethods.value,v=a.user.paymentMethodHistory.value,P=c.filter(H).map(k=>({method:k,isValidForCheckout:u.includes(k),isExpired:k.paymentAttributes.expired,isDisabled:o(k.paymentAttributes)})),S=s?[]:gs({negotiatedPaymentMethods:p,userStoredPaymentMethods:c,paymentMethodHistory:v,isApplePayAvailable:n}),b=[...P.sort((k,_)=>be(k.method,_.method)),...S.sort((k,_)=>be(k.method,_.method))];let f=-1,M="";for(const[k,_]of b.entries()){const x=_.method.lastUsedAt??"";x>M&&(M=x,f=k)}f>0&&b.unshift(...b.splice(f,1));const A=a.session.selectedPaymentMethod.value,D=new Set(h.map(k=>k.id));return b.filter(({method:k})=>H(k)||A&&!H(A)&&k.id===A.id||D.has(k.id)?!0:_s(k))}),this.paymentMethods=I(()=>this.shopPayPaymentMethods.value.map(({method:c,...u})=>{const p=xe(c);return{...u,method:p,canEdit:H(c),canDelete:H(c),canSetDefault:!1,isDefault:!1}})),this.selectedPaymentMethodItem=I(()=>{const c=this.selectedPaymentMethod.value;if(c)return this.paymentMethods.value.find(({method:u})=>u.id===c.id&&u.paymentMethod===c.paymentMethod)}),this.cardPaymentMethods=I(()=>this.paymentMethods.value.filter(c=>G(c.method))),this.activeOrExpiredCardMethods=I(()=>{const c=this.cardPaymentMethods.value,u=[];for(const p of c)s&&p.isDisabled||u.push(p);return u}),this.disabledCardMethodsForInstallments=I(()=>s?this.cardPaymentMethods.value.filter(c=>c.isDisabled):[]),this.isEveryCardDisabled=I(()=>{const c=this.cardPaymentMethods.value;if(c.length===0)return!1;const u=new Set(this.disabledCardMethodsForInstallments.value.map(h=>h.method.id)),p=c.filter(h=>h.isExpired&&!u.has(h.method.id)).length;return c.length===u.size+p}),this.isEveryCardExpired=I(()=>{const c=this.cardPaymentMethods.value;if(c.length===0)return!1;const u=new Set(this.disabledCardMethodsForInstallments.value.map(h=>h.method.id)),p=c.filter(h=>!u.has(h.method.id));return p.length===0?!1:p.every(h=>h.isExpired)});const d=I(()=>{const c=we(this.availablePaymentMethods.value);if(!lt(c))return!1;const u=this.selectedCreditCard.value;return!!(u&&l.value[u.id])});this.msi={binResolution:"server",selectedCardBin:I(()=>{}),clearInstallments:cs,expandedVisible:I(()=>d.value?a.session.paymentMethodOption.value?.name!=="SHOPIFY_INSTALLMENTS":!1),collapsedVisible:I(()=>d.value&&!i.value)}}canShowAsGuestCheckoutMethod(e){const{shopPay:a}=this.deps;return a.visibility.showGuestCheckoutPaymentMethods&&!(e.type==="wallet"&&(e.name==="SHOP_PAY"||e.name==="SHOPIFY_INSTALLMENTS"))}async selectPaymentMethod(e,a="programmatic",s){const{shopPay:n,updateCheckoutAddress:r,shippingRequired:o}=this.deps;if(!e)return n.session.clearPaymentMethod(),{status:"handled",effects:re};const l=tt(e,n.user.paymentMethods.value);if(!l)return{status:"not-handled"};if(a==="buyer"&&this.recordPaymentMethodSelected(e),G(e)){const d=this.selectCreditCard({id:e.paymentAttributes.id});return He(l,n.user.paymentMethods.value,ye(l,this.availablePaymentMethods.value))&&this.#e(l,s),await d,{status:"handled",effects:re}}const i=ye(l,this.availablePaymentMethods.value);return He(l,n.user.paymentMethods.value,i)&&this.#e(l,a==="buyer"?{...s,buyerInitiated:!0}:s),(us(l)||ms(l)||hs(l)||ps(l))&&await r({billingAddress:n.session.selectedBillingAddress.value?.address,fallbackPhoneNumber:n.user.phoneNumber.value},o.value),{status:"handled",effects:re}}async promoteSelectedPaymentMethod(e){const{shopPay:a}=this.deps,s=ys(e,a.user.paymentMethods.value);return s&&(a.session.selectPaymentMethod(s),a.session.unstable_promotePaymentMethod(s)),{status:"handled",effects:{...re,selectByBuyerKey:fe(e)}}}getSavedCardActiveSubscriptionsLookup(e){const a=this.deps.shopPay.user.paymentMethods.value.filter(H).map(o=>o.paymentAttributes).find(o=>o.id===e.id);if(!a)return;const s={id:a.id,uuid:a.uuid,first:3},n=Aa(wt,s),{shopPayGraphql:r}=this.deps;return{key:n,read(){return r.read(n)?.creditCardActiveSubscriptions?.nodes},async load(){const{data:o}=await r.staticQuery(wt,{variables:s});return o?.creditCardActiveSubscriptions?.nodes??[]}}}async selectCreditCard({id:e}){const{shopPay:a}=this.deps,s=a.user.paymentMethods.value.filter(H).map(o=>o.paymentAttributes).find(o=>o.id===e);if(!s)return;const{updateCheckoutAddress:n,fallbackPhoneNumber:r}=this.deps;a.session.selectPaymentMethod({id:s.id,lastUsedAt:s.lastUsedAt,paymentMethod:"CREDIT_CARD",paymentAttributes:s}),this.clearShopPayPaymentLines(),await n({billingAddress:s.billingAddress.address,fallbackPhoneNumber:r})}async deleteCreditCard({id:e}){return this.deleteCreditCardById({id:e})}async updateCreditCard({id:e,billingAddress:a,nickname:s}){const{shopPay:n,updateCreditCard:r,checkoutContext:o,markShopCashStatesStale:l,observability:i}=this.deps,d=n.user.paymentMethods.value.filter(H).map(u=>u.paymentAttributes).find(u=>u.id===e);if(!d)return{status:"failed"};const c=await r(a,e,d.uuid,o,s);if(c.status==="success"&&c.creditCard){const{creditCard:u}=c;n.user.updateCreditCard(e,u),this.selectCreditCard({id:u.id}).catch(p=>{i.error(p)})}if(l(),c.status!=="success"){const u=fs();return cn({addressErrors:u,shopPayErrors:c.errors,i18n:this.deps.i18n,observability:i,userEvents:this.deps.userEvents,source:this.deps.source,configuration:this.deps.checkout.configuration,shop:this.deps.shop,addressContext:"payment-method",submittedAddress:a}),{status:"failed",addressErrors:Object.fromEntries(Object.entries(u).map(([h,v])=>[h,v.value]))}}return{status:"success"}}async addCreditCard({sessionId:e,billingAddress:a,nickname:s,debitOnly:n=!1,isBlocking:r=!1}
2){const{createCreditCard:o,checkoutContext:l,markShopCashStatesStale:i,observability:d}=this.deps;if(e==="")return d.error(new kn("ShopPayPaymentMethodManager: addCreditCard called with empty sessionId")),{status:"failed"};const c=await o(a,e,l,s),u=await this.handleNewCardResponse(c,n,r);return i(),u}async completeCreditCardVerificationAndVault({verificationId:e,billingAddress:a,nickname:s,debitOnly:n=!1,isBlocking:r=!1}){const{completeCreditCardVerification:o,markShopCashStatesStale:l}=this.deps,i=await o(a,e,s),d=await this.handleNewCardResponse(i,n,r);return l(),d}dispose(){}async deleteCreditCardById({id:e,uuid:a}){const{shopPay:s,deleteCreditCard:n,updateCheckoutAddress:r,emptyAddress:o,fallbackPhoneNumber:l,checkoutContext:i,markShopCashStatesStale:d}=this.deps,c=a??s.user.paymentMethods.value.filter(H).map(b=>b.paymentAttributes).find(b=>b.id===e)?.uuid;if(!c)return{status:"failed"};const u=s.session.selectedPaymentMethod.value,p=u&&H(u)?u.paymentAttributes.uuid:void 0,h=await n(e,c,i);if(h.status!=="success"&&!Ln(h))return{status:"failed"};const v=s.user.paymentMethods.value.filter(H).map(b=>b.paymentAttributes).filter(b=>b.uuid!==c);if(s.user.removeCreditCard(e),d(),p!==c)return{status:"success"};const P=Cs(v);if(P)s.session.selectPaymentMethod({id:P.id,lastUsedAt:P.lastUsedAt,paymentMethod:"CREDIT_CARD",paymentAttributes:P}),this.clearShopPayPaymentLines();else{const b=this.paymentMethods.value.find(({method:f,isValidForCheckout:M,isDisabled:A,isExpired:D})=>M&&!A&&!D&&Sn(f))?.method;if(b){const f=tt(b,s.user.paymentMethods.value);f&&this.#e(f)}else s.session.clearPaymentMethod(),this.clearShopPayPaymentLines(),s.session.unstable_updateSelectedBillingAddress(s.session.selectedShippingAddress.value)}const S=P?P.billingAddress.address:s.session.selectedBillingAddress.value?.address;return await r({billingAddress:S??o.value,fallbackPhoneNumber:l}),{status:"success"}}recordPaymentMethodSelected(e){const{observability:a,userEvents:s,source:n,checkout:r,shop:o}=this.deps,l=e.paymentMethod.toLowerCase(),{paymentMethodName:i,paymentBrands:d}=En(e,this.availablePaymentMethods.value);a.counter({name:"payment_method_selected",value:1,attributes:{payment_method_type:l,payment_method_name:i,payment_brands:d,location:"shop_pay_payment_selector",is_mobile:vs()}}),s.monorailEvent({schemaId:"shopify_pay_payment_page_ui_interaction/1.2",payload:{...ta(n,r,o),action:"payment_method_selected",paymentMethodName:i}})}async handleNewCardResponse(e,a,s){const{shopPay:n,markShopCashStatesStale:r}=this.deps;if(e.status==="success"&&e.creditCard){if(a&&e.creditCard.funding!=="debit")return await this.deleteCreditCardById({id:e.creditCard.id,uuid:e.creditCard.uuid}),{status:"failed",errors:[{field:["",ma.DebitOnly],message:""}]};await this.refreshPaymentMethodsFromBuyerDetails()||n.user.addCreditCard(e.creditCard),s?await this.selectCreditCardAndSetPaymentLine({id:e.creditCard.id}):this.selectCreditCardAndSetPaymentLine({id:e.creditCard.id}).catch(l=>{this.deps.observability.error(l)}),r()}return e}async refreshPaymentMethodsFromBuyerDetails(){const{shopPay:e,refreshBuyerDetails:a,paymentRequiredMethod:s,observability:n}=this.deps;try{const r=await a();return r.status!=="success"?!1:(e.updatePaymentMethodsFromBuyerDetails(r,{negotiatedPaymentMethods:this.availablePaymentMethods.value,paymentRequiredMethod:s}),!0)}catch(r){return n.error(r instanceof Error?r:new wn("Failed to refresh Shop Pay buyer details")),!1}}async selectCreditCardAndSetPaymentLine({id:e}){const a=Qt(this.deps.proposedPaymentLines.value)!==void 0,s=this.selectCreditCard({id:e});if(a)return s;const{shopPay:n}=this.deps,r=n.session.selectedPaymentMethod.value;r&&H(r)&&r.paymentAttributes.id===e&&He(r,n.user.paymentMethods.value,ye(r,this.availablePaymentMethods.value))&&this.#e(r),await s}#e(e,a){const{shopPay:s,setPaymentLine:n,observability:r}=this.deps;Ea(()=>{s.session.selectPaymentMethod(e);const o=bs({paymentMethod:e,negotiatedPaymentMethods:this.availablePaymentMethods.value,observability:r});o!==void 0&&(a?n(o,void 0,a):n(o))})}clearShopPayPaymentLines(){const{proposedPaymentLines:e}=this.deps;e.value=e.value.filter(a=>!aa([a],"SHOP_PAY"))}}function Dn(){const t=xn(),{newCardSignal:e,hasLoadedSignal:a}=$e(),s=e.value,n=a.value,{value:r}=Y().paymentLines,o=r?.lines?.find(l=>l.method.type==="direct");return t.value&&!n&&o&&(a.value=!0,!s&&o.method.paymentMethodIdentifier&&(e.value=o.method)),e}function xn(){const t=L().checkout.configuration.layout.isOnePage.value,{paymentMethods:e}=Y();return B(()=>t?!!sa(e.value).length:!1)}const Tn={id:"3880e4a8c616318ac48c829cc40108d16984c1d3172697b99437ce6c20b93d90",type:"mutation",name:"CreditCardCreate",source:"mutation CreditCardCreate($billingAddress:AddressInput!,$origin:String!,$sessionId:ID!,$nickname:String,$checkoutContext:CheckoutContextInput!){credit
2CardCreate(billingAddress:$billingAddress origin:$origin sessionId:$sessionId nickname:$nickname checkoutContext:$checkoutContext){creditCard{...CreditCardFragment __typename}threeDSecureAuthenticationRequest{redirectUrl verificationId __typename}userErrors{field message __typename}__typename}}fragment CreditCardFragment on CreditCard{bank brand expired expiring expiryMonth expiryYear funding id uuid lastDigits lastUsedAt name nickname preferred supportsInstallmentsInterestLoan supportsInstallmentsSplitPayLoan installmentsInterestLoanNotSupportedReason installmentsSplitPayLoanNotSupportedReason verified billingAddressValid billingAddress{addressLineComponents{additionalInformation district streetName streetNumber subdistrict __typename}fields{key value __typename}__typename}__typename}"};function Rn(){const{checkout:{address:{extendedAddressMode:t}},graphql:{shopPayGraphql:e},source:a}=L(),s=ge({source:a});return E(async(n,r,o,l,i=s)=>{const{data:d,error:c}=await e.mutate(Tn,{variables:{billingAddress:mt(n,t),origin:i,sessionId:r,nickname:l,checkoutContext:o}});if(c||d==null||d.creditCardCreate==null)return{status:"failed"};const{creditCardCreate:u}=d;return na(u.userErrors)?{status:"blocked_by_autopay"}:u.userErrors.length>0?{status:"failed",errors:u.userErrors}:u.threeDSecureAuthenticationRequest?{status:"requires_redirect",threeDSecureAuthenticationRequest:u.threeDSecureAuthenticationRequest}:{status:"success",creditCard:u.creditCard?ht(u.creditCard):void 0}},[s,t,e])}const Bn={id:"76ca67a0ff58d1f46e17614ed9f8bb5a075b761270a53c607c2dea3f863acf40",type:"mutation",name:"CreditCardCompleteVerificationAndVault",source:"mutation CreditCardCompleteVerificationAndVault($verificationId:ID!,$billingAddress:AddressInput!,$origin:String,$nickname:String){creditCardCompleteVerificationAndVault(verificationId:$verificationId billingAddress:$billingAddress origin:$origin nickname:$nickname){creditCard{...CreditCardFragment __typename}userErrors{field message __typename}__typename}}fragment CreditCardFragment on CreditCard{bank brand expired expiring expiryMonth expiryYear funding id uuid lastDigits lastUsedAt name nickname preferred supportsInstallmentsInterestLoan supportsInstallmentsSplitPayLoan installmentsInterestLoanNotSupportedReason installmentsSplitPayLoanNotSupportedReason verified billingAddressValid billingAddress{addressLineComponents{additionalInformation district streetName streetNumber subdistrict __typename}fields{key value __typename}__typename}__typename}"};function Fn(){const{checkout:{address:{extendedAddressMode:t}},graphql:{shopPayGraphql:e},source:a}=L(),s=ge({source:a});return E(async(n,r,o,l=s)=>{const{data:i,error:d}=await e.mutate(Bn,{variables:{verificationId:r,billingAddress:mt(n,t),origin:l,nickname:o}});if(d||i==null||i.creditCardCompleteVerificationAndVault==null)return{status:"failed"};const{creditCardCompleteVerificationAndVault:c}=i;return na(c.userErrors)?{status:"blocked_by_autopay"}:c.userErrors.length>0?{status:"failed",errors:c.userErrors}:{status:"success",creditCard:c.creditCard?ht(c.creditCard):void 0}},[s,t,e])}const Un={id:"d60ca8058fb85d0d4e3d3585e353d4317aa417ae9568973bb43da35ca94acce7",type:"mutation",name:"CreditCardDelete",source:"mutation CreditCardDelete($id:ID!,$origin:String!,$uuid:String!,$checkoutContext:CheckoutContextInput!){credit
2CardDelete(id:$id uuid:$uuid origin:$origin checkoutContext:$checkoutContext){userErrors{field message __typename}__typename}}"};function Vn(){const{graphql:{shopPayGraphql:t},source:e}=L(),a=ge({source:e});return E(async(s,n,r,o=a)=>{const{data:l,error:i}=await t.mutate(Un,{variables:{id:s,uuid:n,origin:o,checkoutContext:r}});if(i||l==null||l.creditCardDelete==null)return{status:"failed"};const{creditCardDelete:d}=l;return d.userErrors.length>0?{status:"failed",errors:d.userErrors}:{status:"success"}},[a,t])}function On(t,{checkoutVersion:e,checkoutIdentifier:a,shopifyDomain:s,shopId:n,redirectSource:r},{cache:o=!0}={}){return t.staticQuery(sn,{variables:{checkoutContextInput:{checkoutVersion:e,checkoutIdentifier:a,shopifyDomain:s,shopId:n},shopifyDomain:s,redirectSource:r??void 0},cache:o})}function $n(){const{graphql:{shopPayGraphql:t},source:e,shop:{myshopifyDomain:a,id:s},shopPay:{config:n}}=L(),{checkoutSessionIdentifier:r}=e,o=ge({source:e}),{redirectSource:l}=n;return E(async()=>{const{data:i,error:d}=await On(t,{checkoutVersion:o,checkoutIdentifier:r??"unknown",shopifyDomain:a,shopId:Fe(s),redirectSource:l},{cache:!1});return d||i==null||i.checkoutSession==null||i.checkoutSession.user==null?{status:"failed"}:nn(i)},[r,o,l,s,a,t])}const Kn={id:"0e9fd59cad63a6cd040eec702de445aa95c0d9f613f732e94dce615a476c9d59",type:"mutation",name:"CreditCardUpdate",source:"mutation CreditCardUpdate($billingAddress:AddressInput!,$id:ID!,$uuid:String!,$origin:String!,$nickname:String,$checkoutContext:CheckoutContextInput!){credit
2CardUpdate(billingAddress:$billingAddress id:$id uuid:$uuid origin:$origin nickname:$nickname checkoutContext:$checkoutContext){userErrors{field message __typename}creditCard{...CreditCardFragment __typename}__typename}}fragment CreditCardFragment on CreditCard{bank brand expired expiring expiryMonth expiryYear funding id uuid lastDigits lastUsedAt name nickname preferred supportsInstallmentsInterestLoan supportsInstallmentsSplitPayLoan installmentsInterestLoanNotSupportedReason installmentsSplitPayLoanNotSupportedReason verified billingAddressValid billingAddress{addressLineComponents{additionalInformation district streetName streetNumber subdistrict __typename}fields{key value __typename}__typename}__typename}"};function Gn(){const{checkout:{address:{extendedAddressMode:t}},graphql:{shopPayGraphql:e},source:a}=L(),s=ge({source:a});return E(async(n,r,o,l,i,d=s)=>{const{data:c,error:u}=await e.mutate(Kn,{variables:{id:r,uuid:o,billingAddress:mt(n,t),origin:d,nickname:i,checkoutContext:l}});if(u||!c?.creditCardUpdate)return{status:"failed"};const{creditCardUpdate:p}=c;return p.userErrors.length>0?{status:"failed",errors:p.userErrors}:{status:"success",creditCard:p.creditCard?ht(p.creditCard):void 0}},[s,t,e])}function Yn(t){const{geolocation:e}=Oa(),{shopPay:a,checkout:s}=L(),n=a.user.phoneNumber.value,r=a.user.addresses.value,o=s.configuration.addressSettings.nonBillingAddressSettings.value,l=r[0]?.address,i=o.defaultShippingDetails.country?.code??e.country.code;return ae(()=>{const d={firstName:l?.firstName,lastName:l?.lastName,phone:n,countryCode:l?.countryCode||i,zoneCode:l?.zoneCode};return Ss(d,{extendedAddressMode:s.address.extendedAddressMode})},[s.address.extendedAddressMode,t,l,i,n])}const qn={id:"563e8a86083a6c9ad5bd44d3a4db471e3a9919052512d2745d267074d97420fd",type:"mutation",name:"DeleteVaultedCreditCard",source:""},zn={id:"d1f468f7d6684d3133e47cef5cf1ef67ccd2bd916b53203708d85ac3175f1bd0",type:"mutation",name:"UpdateCustomerCreditCard",source:""};class Hn extends Error{constructor(e){super("Failed to update customer credit card payment method",e),this.name="UpdateCustomerCreditCardPaymentMethodError"}}
2class Wn extends Error{constructor(e){super("Failed to delete customer credit card payment method",e),this.name="DeleteCustomerCreditCardPaymentMethodError"}}async function Qn({graphql:t,address:e,extendedAddressMode:a,defaultPaymentMethod:s,token:n,genericError:r}){if(!n)return{token:void 0};try{const{data:o,error:l}=await t.mutate(zn,{variables:{customerCreditCardModificationInput:{token:n,defaultPaymentMethod:s,billingAddress:{streetAddress:Ms(e,{extendedAddressMode:a})}}}});if(!o?.modifyCustomerCreditCardPaymentMethod||l)throw new Hn({cause:l});const{result:i,errors:d}=o.modifyCustomerCreditCardPaymentMethod;return d.length||!i?{token:void 0,error:d[0]?.localizedMessage||r}:{token:i.token}}catch{return{token:void 0,error:r}}}async function jn({graphql:t,token:e,genericError:a}){if(!e)return{token:void 0};try{const{data:s,error:n}=await t.mutate(qn,{variables:{token:e}});if(!s?.deleteCustomerCreditCardPaymentMethod||n)throw new Wn({cause:n});const{result:r,errors:o}=s.deleteCustomerCreditCardPaymentMethod;return o.length||!r?{token:void 0,error:o[0]?.localizedMessage||a}:{token:r.token}}catch{return{token:void 0,error:a}}}function Xn({userEvents:t,shopId:e,checkoutSessionIdentifier:a,card:s}){t.monorailEvent({schemaId:"checkout_vaulted_payment_method_selected/1.0",payload:{shopId:parseInt(Fe(e),10),checkoutSessionIdentifier:a||"",paymentMethodId:parseInt(Fe(s.id),10),paymentInstrumentAccessorId:-1}})}class Jn extends Gt{constructor({managerName:e,methodName:a,identity:s,deployStage:n,isLocalDevelopment:r}){super(`${e}.${a} was called unexpectedly`,{groupingHash:`PaymentMethodManagerUnexpectedMethodCall::${e}::${a}`,metadata:{paymentMethodManager:{managerName:e,methodName:a,identity:s,deployStage:n,isLocalDevelopment:r}}}),this.name="UnexpectedPaymentMethodManagerMethodCallError"}}function pa({observability:t,managerName:e,methodName:a,identity:s,deployStage:n,isLocalDevelopment:r}){if(r||n!=="production"&&n!=="canary")return;const o=new Jn({managerName:e,methodName:a,identity:s,deployStage:n,isLocalDevelopment:r});t.error(o,{severity:"warning"})}const Lt={status:"failed"};class Te{constructor(e){this.disabledCardMethodsForInstallments=N([]),this.isEveryCardDisabled=N(!1),this.canSetCreditCardNickname=N(!1),this.addCreditCardStrategy="direct-session-payment-line",this.deps=e,this.usesCustomerAccountSelectionRule=e.identity==="customerAccount",this.newCard=e.newCard??N(void 0);const{proposal:a}=e,{proposed:s,negotiated:n}=a,{paymentMethods:r}=n.fields,o=n.fields.paymentMethodHistory??N([]);this.availablePaymentMethods=I(()=>r.value??[]),this.promotedMethods=e.paymentMethodPromotions.promoted,this.customerCreditCards=I(()=>Es(this.availablePaymentMethods.value)),this.selectableCustomerCreditCards=I(()=>sa(this.availablePaymentMethods.value)),this.selectablePaypalBillingAgreements=I(()=>(e.displayablePaymentMethods?.value??this.availablePaymentMethods.value).filter(i=>i.type===Pe.PayPal)),this.selectableCustomerBanks=I(()=>this.availablePaymentMethods.value.filter(i=>i.type==="bank"&&i.availableInstruments.length>0)),this.nonCardKnownPaymentMethods=I(()=>ks({paymentMethodHistory:o.value??[],availablePaymentMethods:e.displayablePaymentMethods?.value??this.availablePaymentMethods.value})),this.availableUserStoredPaymentMethods=I(()=>[...Ue([We({card:this.newCard.value,billingAddress:s.billingAddress.value})]),...this.selectableCustomerCreditCards.value.map(i=>At(i,{cvvVerificationEnabled:this.deps.storeVaultGuestCvvVerificationEnabled})),...this.selectablePaypalBillingAgreements.value.map(ws),...sr(this.selectableCustomerBanks.value.map(Is),this.nonCardKnownPaymentMethods.value,this.promotedMethods.value)]),this.autoselectTarget=I(()=>{const i=this.selectableCustomerCreditCards.value.find(h=>h.defaultPaymentMethod),d=i?this.availableUserStoredPaymentMethods.value.find(h=>h.id===i.token):void 0,c=nr(this.availableUserStoredPaymentMethods.value);if(this.usesCustomerAccountSelectionRule){const h=!c||G(c);if(this.deps.storeVaultEnabled&&h&&d)return d}else if(i)return d;if(c)return c;const u=this.selectableCustomerCreditCards.value[0];if(u)return this.availableUserStoredPaymentMethods.value.find(h=>h.id===u.token);const p=this.availableUserStoredPaymentMethods.value.find(h=>!G(h)&&!et(h));return p||this.availableUserStoredPaymentMethods.value.find(et)}),this.proposedSelectedPaymentMethod=I(()=>Zn(s.paymentLines.value,this.availableUserStoredPaymentMethods.value,this.availablePaymentMethods.value,We({card:this.newCard.value,billingAddress:s.billingAddress.value}))),this.selectedPaymentMethod=I(()=>this.proposedSelectedPaymentMethod.value??this.autoselectTarget.value),this.paymentMethods=I(()=>{const i=We({card:this.newCard.value,billingAddress:s.billingAddress.value}),d=[...Ue([i]),...this.customerCreditCards.value.map(u=>At(u,{cvvVerificationEnabled:this.deps.storeVaultGuestCvvVerificationEnabled}))].map(u=>({method:u,isValidForCheckout:!0,isExpired:u.paymentAttributes.expired,isDisabled:!1,...ir({identity:this.deps.identity,storeV
2aultEnabled:this.deps.storeVaultEnabled,card:u})})),c=this.availableUserStoredPaymentMethods.value.filter(u=>!G(u)).map(u=>({method:u,isValidForCheckout:!0,isExpired:!1,isDisabled:!1,canEdit:!1,canDelete:!1,canSetDefault:!1,isDefault:!1}));return rr({cardItems:d,nonCardItems:c,autoselectTarget:this.usesCustomerAccountSelectionRule?this.autoselectTarget.value:void 0})}),this.selectedPaymentMethodItem=I(()=>{const i=this.selectedPaymentMethod.value;if(i)return this.paymentMethods.value.find(({method:d})=>d.id===i.id&&d.paymentMethod===i.paymentMethod)}),this.selectedCreditCard=I(()=>{const i=this.selectedPaymentMethod.value;return G(i)?i.paymentAttributes:void 0}),this.cardPaymentMethods=I(()=>this.paymentMethods.value.filter(i=>G(i.method))),this.activeOrExpiredCardMethods=this.cardPaymentMethods,this.isEveryCardExpired=I(()=>{const i=this.cardPaymentMethods.value;return i.length>0&&i.every(d=>d.isExpired)});const l=I(()=>{const i=we(this.availablePaymentMethods.value);if(!lt(i))return!1;const d=this.selectedCreditCard.value;return d?s.paymentLines.value.some(c=>d.id===W?c.method.type==="direct":c.method.type===Pe.CreditCard&&c.method.token===d.id):!1});this.msi={binResolution:"client",selectedCardBin:I(()=>{const i=this.selectedCreditCard.value;if(i)return i.id===W?this.newCard.value?.creditCardFirstDigits:this.selectableCustomerCreditCards.value.find(d=>d.token===i.id)?.firstDigits}),clearInstallments:Pt,expandedVisible:l,collapsedVisible:l}}async promoteSelectedPaymentMethod(e){const a=As(e,null);return a?(this.deps.paymentMethodPromotions.promote(a),this.selectPaymentMethod(a,"buyer")):{status:"handled",effects:{...re,selectByBuyerKey:fe(e)}}}canShowAsGuestCheckoutMethod(){return!1}async selectPaymentMethod(e,a="programmatic"){if(!e)return{status:"not-handled"};if(!G(e)){const n=ye(e,this.availablePaymentMethods.value);if(!n)return{status:"not-handled"};const r=fe(n);return a==="buyer"?{status:"handled",effects:{...re,selectByBuyerKey:r}}:(this.deps.setPaymentLine(r),{status:"handled",effects:re})}if(a==="buyer")return this.selectCreditCardByBuyer({paymentMethod:e});if(e.id===W)return this.deps.setPaymentLine(W),{status:"handled",effects:re};const s=this.selectableCustomerCreditCards.value.find(n=>n.token===e.paymentAttributes.id);return s?(this.deps.setPaymentLine(De(s)),{status:"handled",effects:re}):{status:"not-handled"}}async deleteCreditCard({id:e}){if(e===W){const{proposed:o}=this.deps.proposal;if(!this.newCard.value)return{status:"failed"};this.newCard.value=void 0,o.acceptPaymentVaulting.value=!1;const l=this.selectableCustomerCreditCards.value[0];if(l)this.deps.setPaymentLine(De(l));else{const i=this.autoselectTarget.value,d=i?ye(i,this.availablePaymentMethods.value):void 0;d?this.deps.setPaymentLine(fe(d)):o.paymentLines.value=o.paymentLines.value.filter(c=>c.method.type!=="direct")}return{status:"success",shouldResetSuggestedBillingAddress:!!l,shouldResetBillingAddressToShipping:this.deps.identity!=="businessCustomer"}}const a=this.selectedPaymentMethod.value,s=G(a)&&a.id===e,n=this.selectableCustomerCreditCards.value.find(o=>o.token!==e),r=await jn({graphql:this.deps.graphql,token:e,genericError:this.deps.i18n.translate("customer_payment_methods.delete_customer_mandate.generic_error")});return r.token?(s&&n&&this.deps.setPaymentLine(De(n)),{status:"success",shouldNegotiatePaymentMethods:!0}):{status:"failed",bannerError:r.error}}async updateCreditCard({id:e,billingAddress:a,defaultPaymentMethod:s=!1}){const n=await Qn({graphql:this.deps.graphql,token:e,address:a,extendedAddressMode:this.deps.extendedAddressMode,defaultPaymentMethod:s,genericError:this.deps.i18n.translate("shipping.address_form.generic_error")});return n.token?{status:"success",shouldNegotiatePaymentMethods:!0}:{status:"failed",bannerError:n.error}}async addCreditCard(){return this.reportUnexpectedUse("addCreditCard"),Lt}async completeCreditCardVerificationAndVault(){return this.reportUnexpectedUse("completeCreditCardVerificationAndVault"),Lt}dispose(){}async selectCreditCardByBuyer({paymentMethod:e}){let a,s,n;if(e.id===W){const r=this.newCard.value;if(!r)return{status:"not-handled"};
2a=W,s=r,n=r.creditCardFirstDigits}else{const r=this.selectableCustomerCreditCards.value.find(o=>o.token===e.paymentAttributes.id);if(!r)return{status:"not-handled"};a=De(r),n=r.firstDigits,Xn({userEvents:this.deps.userEvents,shopId:this.deps.shopId,checkoutSessionIdentifier:this.deps.checkoutSessionIdentifier,card:r})}return this.deps.isMsiAvailable&&(this.deps.proposal.proposed.paymentLines.value=Pt(this.deps.proposal.proposed.paymentLines.value)),{status:"handled",effects:{...re,selectByBuyerKey:a,...s?{selectByBuyerPaymentMethod:s}:{},updateSelectedCardBin:!0,selectedCardFirstDigits:n,preserveExistingBinPrefix:e.id===W,claimMsiBin:this.deps.isMsiAvailable,claimedMsiBin:this.deps.isMsiAvailable?n:void 0,shouldNegotiate:!0}}}reportUnexpectedUse(e){pa({...this.deps,managerName:"CustomerPaymentMethodManager",methodName:e})}}function Zn(t,e,a,s){const n=t.some(r=>r.method.type!=="deferred"&&r.method.type!=="giftCard"&&r.method.type!=="redeemable");for(const r of t){if(r.method.type==="direct"&&s)return s;if(r.method.type==="deferred"){if(n)continue;const l=e.find(et);if(l)return l;continue}if(er(r)){const l=e.filter(G).find(i=>i.id===r.method.token);if(l)return l;continue}if(tr(r)){const l=e.find(i=>i.paymentMethod==="PAYPAL"&&i.variant==="billing_agreement"&&i.vaultedToken===r.method.token);if(l)return l;continue}const o=ar(r,e,a);if(o)return o}}function We({card:t,billingAddress:e}
2){if(!(!t?.brand||!t.creditCardLastFourDigits))return{id:W,paymentMethod:"CREDIT_CARD",paymentAttributes:{id:W,brand:t.brand,expired:!1,expiryMonth:0,expiryYear:0,lastDigits:t.creditCardLastFourDigits,name:t.cardholderName,billingAddress:{address:e??{}}},lastUsedAt:null}}function Ue(t){return t.filter(e=>e!==void 0)}function er(t){return t.method.type===Pe.CreditCard}function tr(t){return t.method.type===Pe.PayPal}function ar(t,e,a){const s=fe(t.method);return e.find(n=>{if(G(n))return!1;const r=ye(n,a);return r?s===fe(r):!1})}function sr(...t){const e=[],a=new Set;for(const s of t)for(const n of s){const r=`${n.paymentMethod}:${n.id}`;a.has(r)||(a.add(r),e.push(n))}return e}function nr(t){return t.reduce((e,a)=>a.lastUsedAt?e?.lastUsedAt?a.lastUsedAt>e.lastUsedAt?a:e:a:e,void 0)}function rr({cardItems:t,nonCardItems:e,autoselectTarget:a}){const s=t.find(({method:h})=>h.id===W),r=[...t.filter(({method:h})=>h.id!==W)].sort((h,v)=>be(h.method,v.method)),o=[...e].sort((h,v)=>be(h.method,v.method)),l=r.filter(Nt),i=o.filter(Nt),d=l.find(({method:h})=>G(h)&&h.paymentAttributes.defaultPaymentMethod),c=[l[0],i[0]].filter(h=>h!==void 0).sort((h,v)=>be(h.method,v.method))[0],p=(a?[...l,...i].find(({method:h})=>h.id===a.id&&h.paymentMethod===a.paymentMethod):void 0)??d??c;return p?[...Ue([s]),p,...r.filter(h=>h!==p),...o.filter(h=>h!==p)]:[...Ue([s]),...r,...o]}function Nt(t){return t.isValidForCheckout&&!t.isExpired&&!t.isDisabled}function ir({identity:t,storeVaultEnabled:e,card:a}){if(a.id===W)return or;if(t==="businessCustomer")return Qe;const{paymentAttributes:s}=a;return e?s.expired?s.deletable?{canEdit:!1,canDelete:!0,canSetDefault:!1,isDefault:!!s.defaultPaymentMethod}:Qe:{canEdit:!0,canDelete:!!s.deletable,canSetDefault:!0,isDefault:!!s.defaultPaymentMethod}:Qe}const Qe={canEdit:!1,canDelete:!1,canSetDefault:!1,isDefault:!1},or={canEdit:!1,canDelete:!0,canSetDefault:!1,isDefault:!1},Re={status:"failed"};class dr{constructor(e){this.availablePaymentMethods=N([]),this.availableUserStoredPaymentMethods=N([]),this.paymentMethods=N([]),this.selectedPaymentMethod=N(void 0),this.selectedPaymentMethodItem=N(void 0),this.selectedCreditCard=N(void 0),this.activeOrExpiredCardMethods=N([]),this.disabledCardMethodsForInstallments=N([]),this.isEveryCardDisabled=N(!1),this.isEveryCardExpired=N(!1),this.cardPaymentMethods=N([]),this.promotedMethods=N([]),this.msi={binResolution:"client",selectedCardBin:N(void 0),clearInstallments:a=>a,expandedVisible:N(!1),collapsedVisible:N(!1)},this.newCard=N(void 0),this.canSetCreditCardNickname=N(!1),this.addCreditCardStrategy="vault-and-select",this.unexpectedUseOptions=e}canShowAsGuestCheckoutMethod(){return!1}async selectPaymentMethod(){return this.reportUnexpectedUse("selectPaymentMethod"),{status:"not-handled"}}async promoteSelectedPaymentMethod(){return this.reportUnexpectedUse("promoteSelectedPaymentMethod"),{status:"not-handled"}}async deleteCreditCard(){return this.reportUnexpectedUse("deleteCreditCard"),Re}async updateCreditCard(){return this.reportUnexpectedUse("updateCreditCard"),Re}async addCreditCard(){return this.reportUnexpectedUse("addCreditCard"),Re}async completeCreditCardVerificationAndVault(){return this.reportUnexpectedUse("completeCreditCardVerificationAndVault"),Re}dispose(){}reportUnexpectedUse(e){pa({...this.unexpectedUseOptions,managerName:"FallbackPaymentMethodManager",methodName:e})}}function Ci({enableAutoSelect:t=!0}={}){const{source:e,environment:a,checkout:s,shop:n,i18n:r,observability:o,userEvents:l,shopPay:i,graphql:{coreGraphql:d,shopPayGraphql:c}}=L(),u=s.identity.current.value,p=n.hasFlagEnabled(Ls),h=a.devMode!=null,v=Rn(),P=Fn(),S=Vn(),b=$n(),f=Gn(),M=ge({source:e}),A=Yn(),D=se(),{paymentLines:k}=D,_=Dn(),{buyerHasActedSignal:x,newCardSignal:V}=$e(),R=qt(tn),F=i.user.phoneNumber.value,T=Y(),g=Xs(),q=i.session.isInstallmentsSelected.value,J=Js({isApplePayAvailable:g.value}),Z=Ns(),{creditCardDisabled:$}=rn(),Q=an(),{updateCheckoutAddress:z}=Zs(),[,me]=en({allowPreselect:!1}),oe=we(T.paymentMethods.value??[]),de=lt(oe),he=ra(),{eligibilityByCardId:pe}=Ds(dn),_e=E(()=>{R&&(R.cashbackState.stale.value=!0)},[R]),Se=ae(()=>({checkoutIdentifier:e.checkoutSessionIdentifier??"",checkoutVersion:M,shopId:Fe(n.id),shopifyDomain:n.myshopifyDomain}),[e.checkoutSessionIdentifier,n.id,n.myshopifyDomain,M]),K=ae(()=>{const Ce=()=>new Nn({shopPay:i,negotiatedPaymentMethods:T.paymentMethods,installmentsPaymentMethodSelected:q,isApplePayAvailable:g.value,filteredNegotiatedPaymentMethods:J.value,isCreditCardDisabled:$,setPaymentLine:me,updateCheckoutAddress:z,shippingRequired:s.isShippingRequired,i18n:r,observability:o,userEvents:l,source:e,checkout:s,shop:n,createCreditCard:v,deleteCreditCard:S,updateCreditCard:f,completeCreditCardVerification:P,refreshBuyerDetails:b,markShopCashStatesStale:_e,shopPayGraphql:c,emptyAddress:A,proposedPaymentLines:k,checkoutContext:Se,fallbackPhoneNumber:F,paymentRequiredMethod:Q.value,msiEligibilityByCardId:pe,hasSellingPlan:he});return u==="shopPay"?Ce():u==="customerAccount"||u==="businessCustomer"?new Te({proposal:s.proposal,newCard:_,displayablePaymentMethods:Z,paymentMethodPromotions:s.paymentMethodPromotions,setPaymentLine:me,isMsiAvailable:de,shopId:n.id,checkoutSessionIdentifier:e.checkoutSessionIdentifier,storeVaultEnabled:n.storeVaultEnabled,storeVaultGuestCvvVerificationEnabled:n.storeVaultGuestCvvVerificationEnabled,graphql:d,extendedAddressMode:s.address.extendedAddressMode,i18n:r,observability:o,userEvents:l,identity:u,deployStage:a.deployStage,isLocalDevelopment:h}):new dr({observability:o,identity:u,deployStage:a.deployStage,isLocalDevelopment:h})},[u,a.deployStage,h,i,T.paymentMethods,q,g.value,J.value,Z,$,de,me,z,s,o,l,e,n,r,d,c,v,S,b,f,P,_e,A,k,_,Se,F,Q.value,pe,he]);U(()=>()=>K.dispose(),[K]);const y=K.selectedPaymentMethod.value,C=K.paymentMethods.value,w=K.availablePaymentMethods.value,O=K.availableUserStoredPaymentMethods.value,
2j=k.value.some(Ce=>Ce.method.type==="direct");U(()=>{if(!t||u!=="shopPay"||y&&An({selected:y,paymentMethods:C,availablePaymentMethods:w})||j)return;const Ce=C.filter(({isValidForCheckout:ue})=>ue).sort((ue,Ye)=>be(ue.method,Ye.method)).map(({method:ue})=>ue),Me=Mn(Ce);Me&&G(Me)&&Me.paymentAttributes.expired&&l.monorailEvent({schemaId:"shopify_pay_payment_page_ui_interaction/1.1",payload:{...ta(e,s,n),action:"final_payment_method_expired_after_merchant_filter"}});const Ct=Me?tt(Me,i.user.paymentMethods.value):void 0;if(Ct)i.session.selectPaymentMethod(Ct);else{const ue=p?"unavailable":"explicit",Ye=i.session.clearPaymentMethod(ue),vt=i.user.creditCards.peek().length;Ye&&vt>0&&o.log("shop_pay_payment_method_auto_cleared","[usePaymentMethodManager] No listed payment method was valid for checkout, so the Shop Pay selection was cleared",{checkout_session_identifier:e.checkoutSessionIdentifier,source_type:e.type,clear_reason:ue,held_card_count:vt,listed_method_count:C.length,valid_for_checkout_count:Ce.length,negotiated_direct_present:!!oe})}},[t,w,O,s,u,oe,o,l,C,p,y,n,i.session,i.user.creditCards,i.user.paymentMethods.value,e,j]);const ee=x.value,Le=!!V.value,le=K instanceof Te?K.autoselectTarget.value:void 0,Ne=K instanceof Te?K.proposedSelectedPaymentMethod.value:void 0,yt=k.value[0],Ge=yt?.method.type,ft=on(yt);return U(()=>{t&&(u!=="customerAccount"&&u!=="businessCustomer"||ee||K instanceof Te&&le&&(Le||ft||Ne&&Ne.paymentMethod===le.paymentMethod&&Ne.id===le.id||(Ge&&o.log("payment_method_manager_programmatic_selection_replaced_primary_line","Programmatic payment method selection replaced the proposed primary payment line",{replacedPaymentLineMethodType:Ge,replacingPaymentMethodType:le.paymentMethod}),K.selectPaymentMethod(le,"programmatic").catch(()=>{}))))},[t,u,ee,Le,K,le,Ne,ft,Ge,o]),K}function vi(){const{shop:t,checkout:e,observability:a}=L(),s=e.wallets.activeSession.value,n=e.latestReceipt.value,{persistedPayPalSignal:r}=ea(),o=e.identity.current.value==="payPal",l=n?.id,i=$a().value,d=i!==void 0,c=Ke(),u=r.value,{negotiate:p}=ct(),h=Ka(),v=Ht(new Set(xs))?.hasError&&l!==u?.receiptIdForClearedToken,P=Ga("PAYPAL_EXPRESS").value?.merchantId?.trim(),S=i?.method.walletContent?.merchantId?.trim(),f=t.hasFlagEnabled(Ts)&&P&&S&&S!==P,M=u?.billingAgreementStatus&&Rs({checkout:e})&&u.billingAgreementStatus==="NOTREQUESTED"&&!i?.method.walletContent?.isVaultWithPurchaseOrder,A=i?.method.walletContent?.isVaultWithPurchaseOrder===!0&&c.value?.amount===0;U(()=>{function D(){const _={...r.value,receiptIdForClearedToken:v?l:void 0,newTokenRequiredDueToError:!0,billingAgreementStatus:void 0};r.value=_}function k(){let _;v?_="SubmitForCompletion Error":f?_="Gateway Mismatch":A?_="Zero Payment Due":_="Subscription Added",a.counter({name:"paypal_token_cleared",value:1,attributes:{clearReason:_}}),a.log("paypal_token_cleared","Clearing PayPal token due to error",{clearReason:_})}d&&((v||f||M||A)&&(k(),D()),(async()=>(A||v&&!o&&!s)&&(h(),await p({silenceViolations:["non-stock"]})))())},[v,d,f,l,a,r,M,A,o,h,p,s])}function lr(t){const e=Y().paymentMethods;return B(()=>{const s=!!t.value?.balance?.amount,n=!!e.value?.find(r=>r.type==="redeemable"&&r.redemptionSource==="STORE_CREDIT");return!!(s&&n)})}var ie=(t=>(t.Init="init",t.Loading="loading",t.Success="success",t.Error="error",t.Stale="stale",t))(ie||{});function Ve(t,e){return t.filter(a=>!fa(a,e))}function ya(t,e){return t.some(a=>fa(a,e))}function cr({firstOrderTotal:t,storeCreditAccount:e,includeExhausted:a=!1}){if(!t||!e||t.currencyCode!==e.balance.currencyCode)return;const s=e.balance.amount-t.amount;if(!(s<=0&&!a))return{amount:Math.max(s,0),currencyCode:e.balance.currencyCode}}function fa(t,e){return pt(t)&&t.method.redemptionContent&&"storeCreditAccountId"in t.method.redemptionContent&&t.method.redemptionContent.storeCreditAccountId===e.id}function ur(t){const e=Y().paymentLines;return B(()=>{const a=t.value;return!a||!e.value?.lines?!1:ya(e.value.lines,a)})}function mr(){const{shop:{currencyCode:t}}=L(),a=Y().buyerIdentity;return B(()=>{const s=a.value,n=s?.presentmentCurrency||t;return(s?.customerProfile?.__typename==="CustomerProfile"||s?.customerProfile?.__typename==="BusinessCustomerProfile"?s.customerProfile.storeCreditAccounts:[]).find(o=>o.balance.currencyCode===n)})}function bi(){const t=Y().paymentLines;return B(()=>t.value?.lines.filter(e=>pt(e))||[])}
2const hr=new Set(["Image","Banner","s-image","s-banner"]);function pr({options:t,paymentMethodExtension:e}){const a=e[0]?.extension;if(!a)return null;const s=a.appId.split("/").pop(),n=s&&!un.includes(s);return m(Ya,{options:t,customizations:e,transformComponents:n?yr:void 0})}const yr=qa(hr);function fr(){const t=Y().allViolations,e=B(()=>(t.value??[]).filter(s=>!!(za(s)||Bs(s)))),a=B(()=>{const[s]=e.value;return s?s.localizedMessage||s.nonLocalizedMessage:null});return m(Oe,{when:a,children:s=>m(jt,{tone:"critical",errorType:Xt.DiscountError,children:s})})}function Cr({amount:t,maskedIdentifier:e,remove:a}){const{i18n:s}=L(),n=s.formatCurrency(t.amount,{currency:t.currencyCode,form:"short"}),r=e.slice(-4).toUpperCase(),o=s.translate("payment.gift_card_wrapper.gift_card_label",{identifier:Ha(r)}),l=s.translate("order_summary.gift_card_ending",{last_characters:r||""});return m(ke,{borderRadius:"base",background:"base",border:"base",blockAlignment:"center",padding:"small-200",children:m(ze,{gridAutoFlow:"column",gridTemplateColumns:"minmax(0, 1fr) minmax(auto, max-content)",gridTemplateRows:"minmax(0, 1fr)",children:[m(ze,{gridAutoFlow:"column",gridTemplateColumns:"minmax(auto, max-content) minmax(auto, max-content)",gridTemplateRows:"minmax(0, 1fr)",gap:"small-300",alignItems:"center",alignContent:"center",children:[m(ca,{type:"gift-card"}),m(Jt,{children:[m(ne,{accessibilityVisibility:"hidden",children:o}),m(ne,{accessibilityVisibility:"exclusive",children:l})]})]}),m(ze,{gridAutoFlow:"column",gridTemplateColumns:"minmax(auto, max-content) minmax(auto, max-content)",gridTemplateRows:"minmax(0, 1fr)",gap:"small-100",alignItems:"center",alignContent:"center",children:[m(ne,{type:"strong",children:n}),m(Wa,{onClick:()=>a(),accessibilityLabel:s.translate("general.remove_item",{label:l}),children:m(dt,{type:"x",size:"small"})})]})]})})}const Dt="gift_card_option";function Pi({afterAppliedRedeemablesChange:t,autoSelect:e=!1,showHeading:a=!0}){const{i18n:s}=L(),{paymentMethod:n,paymentLines:r,submit:o,remove:l,removeAll:i}=Qa(),d=ja("Checkout::GiftCard::Render",n?.uiExtension?[n?.uiExtension]:[]),{value:c}=Ke(),u=c?.amount||0,[p,h]=X([]),[v,P]=X(!1),S=u===0&&r?.length===0,b=async _=>{h(_),_.length===0&&r.length>0&&(await i())?.status==="success"&&t?.()};U(()=>{S?h([]):(r?.length>0||e)&&h([Dt])},[e,r?.length,S]);const f=E(async(_,x)=>{const V=await o(_,x);return V?.status==="success"&&(P(!1),t?.()),V},[t,o]),M=ae(()=>({paymentMethodIdentifier:n?.paymentMethodIdentifier??"",submitRedeemablePaymentLine:f}),[n?.paymentMethodIdentifier,f]),A=_=>{const{cost:x,method:V}=_;if(!x||V.redemptionSource!=="CUSTOM")return null;const R=V.redemptionContent?.redemptionAttributes.reduce((F,T)=>`${F},${T.key}:${T.value}`,"");return m(Cr,{maskedIdentifier:V.redemptionContent?.maskedIdentifier||"",amount:{amount:x.amount,currencyCode:x.currencyCode},remove:async()=>{(await l(V))?.status==="success"&&t?.()}},R)},D=()=>{if(u===0||!d.length||!n)return null;const _=m(pr,{paymentMethodExtension:d,options:M});return!r||r.length===0?_:v?m(ke,{children:[m(ve,{blockSize:"small-500"}),m(te,{gap:"base",children:[m(Je,{level:3,children:s.translate("payment.gift_card_wrapper.apply_another_gift_card_label")}),_]})]}):m(ke,{children:[m(ve,{blockSize:"small-500"}),m(Wt,{textDecoration:"none",onClick:()=>P(!0),children:m(te,{direction:"inline",alignItems:"center",gap:"small-400",children:[m(dt,{type:"plus"}),m(ne,{children:s.translate("payment.gift_card_wrapper.apply_another_gift_card_label")})]})})]})},k=!!r?.length||!!d.length&&!!n;return m(Xa,{id:"3p-gift-card-field",open:k,duration:"slow",children:m(ot,{accessibilityLabel:s.translate("payment.gift_card_wrapper.heading"),children:m(te,{gap:"base",children:[a&&m(Je,{level:2,children:s.translate("payment.gift_card_wrapper.heading")}),m(ua,{name:"gift_card_option_list",values:p,multiple:!0,onChange:b,variant:"block",children:m(Ze,{value:Dt,disabled:S,selectedContent:m(te,{gap:"base",children:[r?.length>0?m(te,{gap:"small-300",children:r.map(A)}):null,m(fr,{}),D()]}),children:s.translate("payment.gift_card_wrapper.apply_gift_card_label")})})]})})})}const Ae="StoreCreditRedemptionCheckbox",je="StoreCreditSubscriptionRenewalsCheckbox";function Ie(t,e){return pt(t)&&t.method.redemptionContent&&"storeCreditAccountId"in t.method.redemptionContent&&t.method.redemptionContent.storeCreditAccountId===e.id}function vr(t,e){if(!(t.status!=="success"&&t.status!=="error"))return t.negotiated?.paymentLines?.lines.find(a=>Ie(a,e))?.cost}function br({paymentLines:t,storeCreditAccount:e,cost:a}){return t.map(s=>
2Ie(s,e)?{...s,cost:a}:s)}function xt({amountDueAtCheckout:t,storeCreditAccount:e}){if(Ca({amountDueAtCheckout:t,storeCreditAccount:e})&&t!=null)return{amount:Math.min(t.amount,e.balance.amount),currencyCode:t.currencyCode}}function Ca({amountDueAtCheckout:t,storeCreditAccount:e}){return t==null||t.currencyCode===e.balance.currencyCode}function Tt({paymentLines:t,storeCreditAccount:e,cost:a}){let s=!1;const n=t.map(r=>{if(!Ie(r,e))return r;if(a==null){if(r.cost==null)return r;const{cost:o,...l}=r;return s=!0,l}return r.cost?.amount===a.amount&&r.cost.currencyCode===a.currencyCode?r:(s=!0,{...r,cost:a})});return s?n:t}function va(t,e,a){if(t.status!=="success"&&t.status!=="error")return!1;const s=t.negotiated?.paymentLines?.lines;return s==null?t.status==="success":ya(s,e)===a}function ba(t){const{negotiate:e}=ct();return E(async()=>new Promise(a=>{e({include:["paymentLines"],fieldsToResolve:["paymentLines"],silenceViolations:["non-store-credit"],runListenersOnError:!0,force:!0,onComplete(s){t.value=s.status==="success"?ie.Success:ie.Error,a(s)}})}),[e,t])}function Pr(t,e){const a=se(),s=ba(e);return E(async()=>{if(!t)return e.value=ie.Error,{result:null,landed:!1};e.value=ie.Loading;const n=a.paymentLines.value,r=n.findIndex(d=>Ie(d,t)),o=n[r];a.paymentLines.value=Ve(n,t);const l=await s(),i=va(l,t,!1);if(o&&!i){const d=Ve(a.paymentLines.value,t);a.paymentLines.value=[...d.slice(0,r),o,...d.slice(r)]}return{result:l,landed:i}},[t,e,a.paymentLines,s])}function gr(t,e){const{i18n:a,shop:s}=L(),n=se(),r=ba(e),o=Y().paymentLines,l=Ke(),i=ia(),d=ra(),c=oa(),u=Y().paymentFlexibilityPaymentTermsTemplate,p=Fs(s),h=Y().isImmediateAmountReducedForRedeemables,v=E(()=>p&&Us({hasSellingPlan:d.value,hasFixedSellingPlan:c.value,paymentTermsTemplateType:u.value?.type}),[p,d,c,u]),P=ce(!1);return zt(()=>{if(!v())return;const S=l.value??i.value,b=n.paymentLines.value;if(!t||!P.current)return;const f=o.value?.lines.find(A=>Ie(A,t))?.cost;if(h?.value){if(f){const A=Tt({paymentLines:b,storeCreditAccount:t,cost:f});A!==b&&(n.paymentLines.value=A)}return}if(f&&f.amount>0){P.current=!1;return}const M=Tt({paymentLines:b,storeCreditAccount:t,cost:xt({amountDueAtCheckout:S,storeCreditAccount:t})});M!==b&&(n.paymentLines.value=M)}),E(async()=>{if(!t)return e.value=ie.Error,{result:null,landed:!1};e.value=ie.Loading;const S=Ve(n.paymentLines.value,t),b=l.value??i.value,f=v(),M=f?xt({amountDueAtCheckout:b,storeCreditAccount:t}):void 0;if(P.current=M!=null,f&&!Ca({amountDueAtCheckout:b,storeCreditAccount:t}))return e.value=ie.Error,Zt({content:a.translate("store_credit_errors.generic_error")}),{result:null,landed:!1};n.paymentLines.value=[...S,{method:{type:"redeemable",redemptionSource:"STORE_CREDIT",redemptionContent:{storeCreditAccountId:t.id}},...M&&{cost:M}}];const A=await r();if(!va(A,t,!0))return P.current=!1,n.paymentLines.value=Ve(n.paymentLines.value,t),{result:A,landed:!1};const D=f&&vr(A,t);return D&&D.amount>0&&(P.current=!1,n.paymentLines.value=br({paymentLines:n.paymentLines.value,storeCreditAccount:t,cost:D})),{result:A,landed:!0}},[i,r,l,n.paymentLines,e,v,t,a])}function _r(t){const{shop:e}=L(),a=e.hasFlagEnabled(da),s=ia(),n=Vs();return B(()=>{if(n.value)return cr({firstOrderTotal:s.value,storeCreditAccount:t.value,includeExhausted:a})})}function gi({afterAppliedRedeemablesChange:t}){const{i18n:e,shop:a,webMcp:s}=L(),n=a.hasFlagEnabled(da),r=Ke(),o=se(),l=Os(),i=oa(),d=mr(),c=ur(d),u=ka(ie.Init),p=lr(d),h=_r(d),v=B(()=>n&&h.value!=null),P=B(()=>l.value||i.value),S=B(()=>{if(l.value)return e.translate("payment.store_credit.buying_gift_card");if(i.value)return e.translate("payment.store_credit.no_fixed_selling_plans")});zt(()=>{(!p.value||!v.value||P.value)&&wa(()=>{o.useStoreCreditForSubscriptionRenewals.value&&(o.useStoreCreditForSubscriptionRenewals.value=!1)})});const b=gr(d.value,u),f=Pr(d.value,u),M=B(()=>u.value===ie.Loading),A=B(()=>M.value||P.value),D=B(()=>A.value||r.value?.amount===0&&!c.value),k=A,_=B(()=>{const $=[],Q=v.value&&o.useStoreCreditForSubscriptionRenewals.value;return(c.value||Q)&&$.push(Ae),Q&&$.push(je),$}),x=E(async $=>{const Q=c.peek(),z=$.includes(Ae),oe=n&&!(Q&&!z)&&$.includes(je),de=z||oe,he=o.useStoreCreditForSubscriptionRenewals.peek();if(o.useStoreCreditForSubscriptionRenewals.value=oe,de!==Q){const{landed:pe}=de?await b():await f();if(!pe){o.useStoreCreditForSubscriptionRenewals.value=de?!1:he;return}t?.()}},[b,f,c,o.useStoreCreditForSubscriptionRenewals,n,t]),V=B(()=>p.value&&!!d.value),R=B(()=>_.value.includes(Ae)),F=E($=>x($?[...new Set([..._.peek(),Ae])]:[]),[_,x]);U(()=>s?.unstable_provideStoreCreditController({available:V,redeeming:R,applied:c,settling:M,hasGiftCard:l,hasFixedSellingPlan:i,paymentDue:r,setRedeeming:F}),[s,V,R,c,M,l,i,r,F]);const T=d.value;if(!V.value||!T)return null;const g=v.value?h.value:void 0,q=T.balance,J=S.value,Z=g&&g.amount>0?e.translate("payment.store_credit.remaining_for_subscription_charges_description",{amount:e.formatCurrency(g.amount,{currency:g.currencyCode})}):void 0;return m(ot,{accessibilityLabel:e.translate("payment.store_credit.label"),children:m(ua,{name:"store_credit_redemption",values:_.value,multiple:!0,onChange:x,variant:"block",children:[m(Ze,{value:Ae,disabled:D.value,secondaryContent:m(ne,{type:"strong",children:e.formatCurrency(q.amount,{currency:q.currencyCode})}),details:J&&m(ne,{children:J}),children:m(te,{direction:"inline",gap:"base",alignItems:"center",children:[m(ne,{children:e.translate("payment.store_credit.apply_label")}),m(Oe,{when:M,children:m(Ja,{})})]})}),g&&m(Ze,{value:je,disabled:k.value,details:(Z||J)&&m(te,{gap:"small-500",children:[Z&&m(ne,{children:Z}),J&&m(ne,{children:J})]}),children:m(ne,{children:e.translate("payment.store_credit.use_remaining_for_subscription_charges_label")})})]})})}function _i(){const{i18n:t}=L(),{hasViolations:e}=Za($s);return e?m(jt,{errorType:Xt.PaymentError,tone:"critical",children:t.translate("store_credit_errors.generic_error")}):null}const Sr="YVGTZ",Mr="zyVks",Ar="U4h7p",Xe={Row:Sr,Name:Mr,Digits:Ar};function Si({name:t,digits:e,icon:a}){return m(te,{className:Xe.Row,direction:"inline",columnGap:"none",rowGap:"small-200",alignItems:"center",inlineSize:"100%",children:[m("span",{className:Xe.Name,children:m(Jt,{children:t})}),m("span",{className:Xe.Digits,children:e}),a]})}const Er=new Map([["american_express","American Express"],["cartes_bancaires","Cartes Bancaires"],["diners_club","Diners Club"],["discover","Discover"],["elo","Elo"],["jcb","JCB"],["master","Mastercard"],["masterdebit","Mastercard"],["unionpay","UnionPay"],["visa","Visa"],["visadebit","Visa"],["maestro","Maestro"]]);function kr(t){const e=Er.get(t.toLowerCase());if(e)return e;const a=t.toUpperCase();return Ks(a)?la(a):t}function Mi(t){return t?t.nickname&&t.nickname.trim().length>0?t.nickname:t.bank&&t.bank.trim().length>0?t.bank:kr(t.brand):""}function wr(){const{paymentLines:t}=se();return B(()=>Qt(t.value))}function Ir({isSelected:t,hasMsiPlan:e,isStale:a,binPrefix:s,canEditBin:n,supportedInstallmentsCount:r,isNegotiating:o}){if(!t||!e&&!a)return"hidden";if(s){if(s.length<8&&n)return"prompt"}else{if(n)return"prompt";if(r===0)return"hidden"}return o||a?"loading":"dropdown"}function Rt({id:t,variant:e}){const{i18n:a}=L(),s=e==="prompt"?a.translate("msi_installments.enter_card_details_prompt"):a.translate("msi_installments.loading_installments");return U(()=>
2{if(e==="loading")return Zt({content:s})},[s,e]),m(ss,{id:t,name:"msiInstallments",label:a.translate("msi_installments.payment_plan_label"),value:e,disabled:e==="loading",onChange:()=>{},children:m(as,{value:e,children:s})})}function Lr({paymentMethod:t,isSelected:e,canEditBin:a=!0,isVaultedContext:s=!1,id:n="msiInstallmentsSelect"}){const{bankIdNumberSignal:r,installmentMonthsSignal:o,lastNegotiatedBinSignal:l}=$e(),{paymentLines:i}=se(),d=wr();U(()=>{o.value=d.value},[d.value,o]);const c=a&&!s,u=t.installmentPlans?.find(S=>S.type==="MSI"),p=u?.supportedInstallments??[],h=Gs(r.value),v=!s&&h!==void 0&&l.value!==void 0&&h!==l.value;U(()=>{if(!d.value)return;(!e||!u||!h&&!c&&p.length===0)&&(i.value=ts(i.value,void 0))},[d.value,e,u,h,c,p.length,i]);const P=Ir({isSelected:!!e,hasMsiPlan:!!u,isStale:v,binPrefix:h,canEditBin:c,supportedInstallmentsCount:p.length,isNegotiating:!1});return P==="hidden"?null:P==="prompt"?m(Rt,{id:n,variant:"prompt"}):m(Rt,{id:n,variant:"loading"})}const Bt=rt({displayName:"MsiInstallmentsSelect",useError:es("MsiInstallmentsSelect"),load:()=>Ia(async()=>({default:(await nt(async()=>{const{MsiInstallmentsSelect:t}=await import("./component-MsiInstallmentsSelect.Di8KHei5.js");return{MsiInstallmentsSelect:t}},__vite__mapDeps([25,1,11,2,3,4,5,12,9,13,14,7,26,27,28,29,30,16,17,18,19,31,32,33,34,35,36,37,38,39,40,41,42]))).MsiInstallmentsSelect})),renderLoading:t=>m(Lr,{...t})}),Ft=new Map,Ee=class Ee{constructor(e=[],a=[],s,n=!1){this.sdkQueue=e,this.initQueue=a,this.sdk=s,this.scriptLoaded=n,this.setupGeneration=0,this.currentSetupId=0}async load(e){let a=Ft.get(e.source);a instanceof Promise||(a=ns(e,!0),Ft.set(e.source,a)),await a,this.initQueue.pop()?.(),this.initQueue=[],this.scriptLoaded=!0}async setup(e,a,s){return Ut(()=>{if(this.sdk)return;if(this.setupPromise&&this.setupForm===e)return this.setupPromise;const n=window.CardFields;if(!n)throw new ut("Attempted to init Cardfields before it is ready");const r=++this.currentSetupId;return this.setupForm=e,s(),this.setupPromise=(async()=>{try{for(let o=0;o<Ee.MAX_SETUP_ATTEMPTS;o++){const l=this.setupGeneration,i=await n.setup(e,a);if(r!==this.currentSetupId){try{i.teardown()}catch{}return}if(l!==this.setupGeneration){try{i.teardown()}catch{}continue}this.sdk=i;for(const d of this.sdkQueue)await d();this.sdkQueue=[];return}throw new gt(`CardFields setup failed: ${Ee.MAX_SETUP_ATTEMPTS} consecutive teardowns raced setup.`)}finally{this.currentSetupId===r&&(this.setupPromise=void 0,this.setupForm=void 0)}})(),this.setupPromise},this.scriptLoaded,this.initQueue)}async teardown(){this.setupGeneration++,this.setupPromise=void 0,this.setupForm=void 0,this.sdk?.teardown(),this.sdk=void 0,this.sdkQueue=[],this.initQueue=[]}on(e,a,s){return this.scheduleSDK(n=>s?n.on(s,e,a):n.on(e,a))}off(e,a,s){return this.scheduleSDK(n=>s?n.off(s,e,a):n.off(e,a))}setStyles({field:e,styles:a}){return e?this.scheduleSDK(s=>s.setStyles(e,a)):this.scheduleSDK(s=>s.setStyles(a))}setFocus(e){return this.scheduleSDK(a=>a.setFocus(e))}setTranslation(e,a){return this.scheduleSDK(s=>s.setTranslation(e,a))}setPlaceholderContent(e,a){return this.scheduleSDK(s=>s.setPlaceholderContent(e,a))}setValue(e,a){return this.scheduleSDK(s=>s.setValue(e,a))}setTooltip(e,a){return this.scheduleSDK(s=>s.setTooltip(e,a))}vaultCard(e){return this.scheduleSDK(a=>a.vaultCard(e))}vaultCardMultipleTimes(e,a){return this.scheduleSDK(s=>s.vaultCardMultipleTimes(e,a))}setErrors(e){return this.scheduleSDK(a=>a.setErrors(e))}clearField(e){return this.scheduleSDK(a=>a.clearField(e))}loadFonts(e){return this.scheduleSDK(a=>a.loadFonts(e))}getFieldFrame(e){return this.scheduleSDK(a=>a._getFieldFrame(e))}scheduleSDK(e){return Ut(()=>{if(!this.sdk)throw new gt("The CardFields SDK has not been set up.");return e(this.sdk)},!!this.sdk,this.sdkQueue)}};Ee.MAX_SETUP_ATTEMPTS=3;let at=Ee;function Ut(t,e,a){if(e){const s=t();return s instanceof Promise?s:new Promise(n=>{n(s)})}return new Promise((s,n)=>{a.push(async()=>{try{const r=t();r instanceof Promise?s(await r):s(r)}catch(r){n(r)}})})}const Pa=Na(void 0),Vt={name:!1,number:!1,expiry:!1,verification_value:!1,issue_number:!1,issue_date:!1};function Nr({children:t,value:e,sdkScriptAttributes:a,blurValidationEnabled:s=!0,blurValidationFieldDenylist:n,onError:r,onSetFieldErrors:o,onLoadSuccess:l}){const i=ae(()=>new at,[]),[d,c]=X(!0),[u,p]=X({name:null,number:null,verification_value:null,expiry:null,issue_date:null,issue_number:null,sdk:null}),h=ce(),[v,P]=X(),[S,b]=X(),[f,M]=X({name:!1,number:!1,expiry:!1,verification_value:!1,issue_number:!1,issue_date:!1}),[A,D]=X(""),[k,_]=X([]),[x,V]=X(Vt),R=ce(x);U(()=>{R.current=x},[x]);const F=ce(),T=E(y=>{h.current=y instanceof rs?y.diagnostics:void 0,p({sdk:y.message}),r?.(y),c(!1)},[r,p,c]),g=E(async y=>{try{return await y()}catch(C){if(C instanceof Error){let w=null;if(C.name===_t.name)w=new _t(C.message);else if(C.name===St.name){const O="httpStatus"in C&&typeof C.httpStatus=="number"?C.httpStatus:void 0;w=new St(C.message,O)}else C.name===Mt.hostedFieldsName&&(w=new Mt(C.message));if(w)return T(w),"";T(C)}throw C}},[T]),q=E(async(y,C={propagateErrors:!0})=>{const{sdk:w,...O}=y;await g(()=>i.setErrors(O)),p(j=>{const ee={...j,...y};return C.propagateErrors&&o?.(ee),ee})},[i,o,g]),J=E((y,C)=>{const w={},O=F.current;C?(y||(!f?.expiry&&C.includes("expiry")&&(w.expiry=O?.expiry),!f?.number&&C.includes("number")&&(w.number=O?.number_blank),!f?.name&&C.includes("name")&&(w.name=O?.name)),(y||C.includes("verification_value"))&&!f?.verification_value&&(w.verification_value=O?.verification_value)):(y||(f?.expiry||(w.expiry=O?.expiry),f?.number||(w.number=O?.number_blank),f?.name||(w.name=O?.name)),f?.verification_value||(w.verification_value=O?.verification_value));const j={...u,...w};return q(j),{isValid:!Object.values(j).some(Boolean)}},[u,f?.expiry,f?.name,f?.number,f?.verification_value,q]);U(()=>{async function y(){try{if(!a)throw new ut("Provider: hostedFieldsUrl must be provided");await i.load(a)}catch(C){C instanceof Error&&T(C)}}y()},[a,i,T]);const Z=E(({cardType:y,bin:C,networks:w})=>{P(y),D(C),_(w)},[]),$=E(({targetName:y})=>{b(y)},[]),Q=E(async y=>{const{isValueValid:C,targetName:w,isValueEmpty:O}=y,j=F.current,ee=R.current[w],Le=!!n?.has(w);if(s&&!Le&&j&&ee){const le={[w]:C?null:j[w]};w==="number"&&O&&(le[w]=j.number_blank),await q(le,{propagateErrors:!1})}b(void 0)},[q,s,n]),z=E(async y=>{const{targetName:C,isValueEmpty:w,isTab:O}=y;if(!O){M(ee=>({...ee,[C]:!w})),V(ee=>({...ee,[C]:!0}));const j={[C]:null};await q(j)}},[q]),me=E(y=>{M(C=>({...C,[y]:!0}))},[]),oe=Dr(),de=E(()=>{oe.current&&(M({name:!1,number:!1,expiry:!1,verification_value:!1,issue_number:!1,issue_date:!1}),_([]))},[M,oe]),he=E(()=>{g(()=>i.on("cardtype",Z)),g(()=>i.on("focus",$)),g(()=>i.on("blur",Q)),g(()=>i.on("keyup",z)),g(()=>i.on("change",z)),g(()=>i.on("input",z))},[g,i,Z,$,Q,z]),pe=E(()=>{g(()=>
2i.off("cardtype",Z)),g(()=>i.off("focus",$)),g(()=>i.off("blur",Q)),g(()=>i.off("keyup",z)),g(()=>i.off("change",z)),g(()=>i.off("input",z))},[g,i,Z,$,Q,z]),_e=E(()=>{V(Vt)},[]),Se=ae(()=>({loadFonts:y=>g(()=>i.loadFonts(y)),setErrors:y=>q(y,{propagateErrors:!1}),setStyles:(...y)=>g(()=>i.setStyles(...y)),setFocus:(...y)=>g(()=>i.setFocus(...y)),setTooltip:(...y)=>g(()=>i.setTooltip(...y)),setTranslation:(...y)=>g(()=>i.setTranslation(...y)),setPlaceholderContent:(...y)=>g(()=>i.setPlaceholderContent(...y)),setValue:(y,C)=>g(()=>(typeof C=="string"&&C.trim().length>0&&M(w=>({...w,[y]:!0})),i.setValue(y,C))),setup:async(y,C,w=()=>{})=>{c(!0),await g(()=>i.setup(y,C,w)),l?.(),c(!1),F.current=C.errorMessages},teardown:()=>g(()=>i.teardown()),clearField:y=>g(()=>(M(C=>({...C,[y]:!1})),i.clearField(y))),vaultCard:(...y)=>g(()=>i.vaultCard(...y)),vaultCardMultipleTimes:(y,C)=>g(()=>i.vaultCardMultipleTimes(y,C)),getCardField:y=>i.getFieldFrame(y)}),[i,q,g,l]);U(()=>()=>{o?.({})},[o]);const K=ae(()=>e??{sdk:Se,errors:u,sdkLoadDiagnostics:h.current,cardBrand:v,bankIdNumber:A,networks:k,focusedField:S,filled:f,loading:d,validate:J,subscribe:he,unsubscribe:pe,resetTouched:_e,emptyFields:de,setFilled:me,touched:x},[Se,v,A,k,u,f,S,d,e,J,he,pe,_e,de,me,x]);return m(Pa.Provider,{value:K,children:t})}function Dr(){const t=ce(!0);return La(()=>()=>{t.current=!1},[]),t}const ga=()=>{const t=qt(Pa);if(t==null)throw new ut("No cardfields found in context");return t},st=6,_a=t=>t.toUpperCase(),Ot=t=>t.toLowerCase();function xr(t){return!!t?.some(e=>e.type==="direct"&&e.paymentBrands.includes("BOGUS"))}function Ai({paymentMethods:t,hasBogusGateway:e=xr(t),paymentLines:a,storeVaultGuestCvvVerificationEnabled:s=!1,selectedCardRequiresProposalLineCvv:n=!1,selectedCardBrand:r,hasAmexCvvOnlyField:o=Tr({paymentLines:a,storeVaultGuestCvvVerificationEnabled:s,selectedCardRequiresProposalLineCvv:n,selectedCardBrand:r})}){return e?new Set(["number"]):o?new Set(["verification_value"]):new Set}function Tr({paymentLines:t,storeVaultGuestCvvVerificationEnabled:e=!1,selectedCardRequiresProposalLineCvv:a=!1,selectedCardBrand:s}){return!!(a&&s?.toUpperCase()==="AMEX"||e&&t?.some(({method:n})=>n.type===Pe.CreditCard&&n.brand==="AMEX"))}function Ei(t){return t.replace(/([\d.]+)rem/g,(e,a)=>`${Number(a)*10/14}rem`)}function ki(){const{paymentMethods:t}=Y();return B(()=>{const e=t.value?.filter(a=>a.type===Pe.CreditCard&&!!a.expired);return e?e.length:0})}function wi(){const{i18n:t}=L();return{getAccessibilityLabel:a=>{const s=a.type==="direct"?a.creditCardLastFourDigits:a.displayLastDigits;return`${la(a.brand)} ${t.translate("payment.saved_credit_card_info")} ${s}`}}}function Sa(t){return t?t.map(e=>_a(e)):[]}function Rr({displayName:t,paymentBrands:e,paymentMethodIdentifier:a,selectableBrands:s,networkSelectionSupported:n}){const{bankIdNumber:r,networks:o,cardBrand:l}=ga(),{userEvents:i,source:{checkoutSessionIdentifier:d}}=L(),[c,u]=X(!1),[p,h]=X(""),v=ae(()=>Sa(o||(l&&(r?.length??0)>=st?[l]:void 0)),[o,l,r]);U(()=>{if(!r||r.length===0||!d)return;const P={checkoutToken:d,paymentMethodIdentifier:a,displayName:t||"",supportedBrands:e.join(","),detectedBrands:v.join(","),cardIsCobadged:v.length>1,shownBrands:s.join(","),networkSelectorShown:s.length>1&&n};c||(i.monorailEvent({schemaId:"checkout_credit_card_number_interaction/1.1",payload:{...P,eventName:"first_digit_entered"}}),u(!0));const S=r.length>=st&&v.length>0,b=P.shownBrands!==p;S&&b&&(h(P.shownBrands),i.monorailEvent({schemaId:"checkout_credit_card_number_interaction/1.1",payload:{...P,eventName:"brand_shown_to_buyer"}}))},[a,t,e,v,s,r,i,d,n,p,c,u])}const Ma=Ys("CreditCardNetworkContext");function Br({children:t,paymentMethod:e,publishesCardNetworkDetection:a=!1}){const{checkout:s,source:n,observability:r,userEvents:o}=L(),l=Da(),i=e?fe(e):l,d=s.cardNetworkSelection.forMethod(i),{bankIdNumber:c,touched:u,...p}=ga(),{networks:h,sdk:v,filled:P}=p,S=ae(()=>Sa(h),[h]),b=c?.replace(/\s/g,"").length??0,f=b>=st&&p.cardBrand?_a(p.cardBrand):void 0,M=ae(()=>S.filter(R=>e?.paymentBrands.includes(R)),[S,e]),A=!!e?.supportsNetworkSelection;U(()=>{a&&d.setDetectedState({networkSelectionEnabled:A,availableNetworks:M,cardBrand:f,numberFilled:!!P.number,bankIdNumberLength:b})},[a,d,A,M,f,P.number,b]);const D=d.selectableBrands.value;Rr({displayName:e?.name,paymentBrands:e?.paymentBrands??[],paymentMethodIdentifier:e?.paymentMethodIdentifier??"",selectableBrands:D,networkSelectionSupported:e?.supportsNetworkSelection??!1});const k=E(R=>{const F=d.selectedSavedCreditCardBrand.value,T=typeof R=="function"?R(F):R;d.setSelectedSavedCreditCardBrand(T)},[d]),_=E(async()=>{const R=d.selectedNetwork.value,F=R?{selected_network:Ot(R)}:void 0,T=await v.vaultCard(F);return $t(o,{checkoutSessionIdentifier:n.checkoutSessionIdentifier??"",selectedNetwork:
2F?.selected_network,detectedNetworks:h}),T||r.log("credit_card_network_context_no_session_id_returned","No session id returned when vaulting card with selected network",{selectedNetwork:F?.selected_network}),T},[d,v,n,h,r,o]),x=E(async R=>{const F=d.selectedNetwork.value,T=F?{selected_network:Ot(F)}:void 0,g=await v.vaultCardMultipleTimes(R,T);return $t(o,{checkoutSessionIdentifier:n.checkoutSessionIdentifier??"",selectedNetwork:T?.selected_network,detectedNetworks:h}),g},[d,v,o,n,h]),V=ae(()=>({activePaymentBrand:d.activeBrand.value,binLength:d.bankIdNumberLength.value,paymentMethod:e,detectedNetworks:S,selectableBrands:D,selectedNetwork:d.selectedNetwork.value,selectedSavedCreditCardBrand:d.selectedSavedCreditCardBrand.value,setSelectedNetwork:d.setSelectedNetwork,setSelectedSavedCreditCardBrand:k,vaultCardWithSelectedNetwork:_,vaultCardMultipleTimesWithSelectedNetwork:x}),[d.activeBrand.value,d.bankIdNumberLength.value,d.setSelectedNetwork,d.selectedNetwork.value,d.selectedSavedCreditCardBrand.value,e,S,D,k,_,x]);return m(Ma.Provider,{value:V,children:t})}function Ii(){return qs(Ma)}function $t(t,{checkoutSessionIdentifier:e,selectedNetwork:a,detectedNetworks:s}){a&&t.monorailEvent({schemaId:"checkout_credit_card_network_selection/1.0",payload:{checkoutToken:e,selectedNetwork:a,supportedNetworks:s?.join(",")??""}})}const Fr=["CardFieldsFetchFailureError"];function Ur({children:t,publishesCardNetworkDetection:e,directPaymentMethodConfig:a,...s}){const n=ce(is()),{value:r}=Y().paymentMethods,o=a??we(r??[]),{observability:l}=L(),i=E(d=>{if(Fr.includes(d.name)){l.log("default_card_fields_provider_unactionable_error","Unactionable error in card fields provider",{error:d});return}l.error(d)},[l]);return m(Nr,{...s,onError:i,sdkScriptAttributes:n.current,children:m(Br,{paymentMethod:o,publishesCardNetworkDetection:e,children:t})})}function Vr({enabled:t,selectedCardId:e}){const{checkout:{identity:a}}=L(),{paymentLines:s}=se(),{negotiate:n}=ct(),r=ln(),o=ce(void 0);U(()=>{if(a.current.value!=="shopPay")return;if(!t||!e){o.current=void 0,s.value=zs(s.value);return}if(o.current===e)return;o.current=e;const i=aa(s.value,"SHOP_PAY")?.method.walletContent?.creditCardInstallments;s.value=Hs(s.value,r({msiEligibleCard:!0,creditCardInstallments:i})),n({include:[]}).catch(()=>{o.current=void 0})},[t,a.current.value,e])}function Li(t){const{shopPay:e}=L(),{value:a}=Y().paymentMethods,{paymentLines:s}=se(),{bankIdNumberSignal:n,installmentMonthsSignal:r}=$e(),{binResolution:o,clearInstallments:l,selectedCardBin:i,expandedVisible:d,collapsedVisible:c}=t.msi,u=d.value,p=c.value,h=o==="server"?t.selectedCreditCard.value?.id:void 0;Vr({enabled:p&&!e.session.isLoading.value,selectedCardId:h});const v=ce(u);U(()=>{v.current&&!u&&(s.value=l(s.value),r.value=void 0),v.current=u},[u,l,s,r]);const P=ce(p);U(()=>{P.current&&!p&&(s.value=l(s.value),r.value=void 0),P.current=p},[p,l,s,r]);const S=i.value,b=t.selectedCreditCard.value?.id;U(()=>{if(o!=="client")return;const D=n.peek();n.value=b===W&&mn(D,S)?D:S},[o,n,S,b]);const f=we(a??[]),M=f&&u?Kt({paymentMethod:f,binResolution:o,id:"msiInstallmentsSelect-expanded"}):void 0,A=f&&p?Or(Kt({paymentMethod:f,binResolution:o,id:"msiInstallmentsSelect-summary"})):void 0;return{expandedSlot:M,collapsedSlot:A}}function Kt({paymentMethod:t,binResolution:e,id:a}){return e==="server"?m(Bt,{paymentMethod:t,isSelected:!0,isVaultedContext:!0,id:a}):m(Bt,{paymentMethod:t,isSelected:!0,canEditBin:!1,id:a})}function Or(t){return m(ke,{paddingInlineStart:"large-100",children:m(Ur,{onSetFieldErrors:()=>{},children:t})})}export{Pr as $,Ii as A,Yn as B,Tr as C,Ur as D,_a as E,Ei as F,Pi as G,wi as H,xn as I,Dn as J,Qn as K,jn as L,Bt as M,ii as N,Xn as O,pr as P,ki as Q,oi as R,_i as S,si as T,ri as U,Si as V,ni as W,ur as X,cr as Y,ie as Z,gr as _,wr as a,Ae as a0,je as a1,vn as a2,Nn as a3,mr as b,lr as c,bi as d,gi as e,Ci as f,Ir as g,Li as h,ai as i,Ai as j,di as k,xr as l,ga as m,Mi as n,G as o,pi as p,mi as q,hi as r,yi as s,li as t,vi as u,En as v,ci as w,ui as x,fi as y,et as z};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.