1import{A as G,h as J,T as E,q as X,m as de,g as ue}from"./2c1ab0fe.BqEHHmaW.js";import{bZ as le,aT as ce,P as Z,b_ as pe,b$ as ye,O as b,Q as $,aX as me,V as j,c0 as he,aY as Pe,c1 as K,c2 as ve,c3 as fe,c4 as ge,c5 as Ce,c6 as Se,c7 as Ae,c8 as V,G as Me,S as be,c9 as Te,aH as _e}from"./4c290a1e.FJVsH4yi.js";import{h as ee,bL as Le,bM as Y,bN as ke}from"./164ad2e3.BA-GikTU.js";import{h as Ie}from"./0a7dffce.BHf0S_6c.js";import{s as Fe,i as Ne}from"./08a3b809.BqMk-s3U.js";class we extends Error{constructor(){super(...arguments),this.name="UnsupportedShopPayCustomerCardError"}}function Je({allowPreselect:e=!0,displayedPaymentMethods:t}={}){const n=le(),{hasNegotiatedAlternativePaymentCurrencySignal:a,newCardSignal:r}=ce(),o=Z(),p=o.paymentMethods,{value:s}=pe(),{negotiate:i}=ee(),P=o.paymentLines,C=ye(),{checkout:{identity:l},observability:c,userEvents:m,shop:te}=b(),{currencyCode:T,id:x,paymentMethodAutoSelectionDisabled:ne}=te,v=l.current.value==="shopPay",S=!v,y=W(t??s,v),{value:ae}=o.buyerIdentity,d=$().paymentLines,{value:U}=o.deferredTotal,{value:H}=o.paymentFlexibilityPaymentTermsTemplate,O=me(),_=ae?.presentmentCurrency||T,oe=Le(),L=G(!1),q=G(!1),A=v?d.value.find(u=>u.method.type===j.CreditCard)?.method.type:void 0;J(()=>{!A||q.current||(q.current=!0,c.counter({name:"shop_pay_unsupported_customer_card_on_payline",value:1,attributes:{payment_method_type:A}}),c.error(new we("Shop Pay proposed payment line contains an unsupported Customer Account saved card"),{severity:"warning",metadata:{value:{paymentMethodType:A}}}))},[c,A]);const f=E(()=>{const u=y.find(he);if(S&&u&&Pe(d.value))return K(u);const g=d.value.filter(h=>ve(h,y,{identity:l})||fe(h)),I=ge(g),[M]=I;return M!==void 0?M:(c.leaveErrorBreadcrumb("Unexpected: Selected payment method is empty because `paymentLines` array is empty",{displayedPaymentMethods:JSON.stringify(y),displayedProposedPaymentLines:JSON.stringify(g)}),"")},[y,l,c,d.value,S]),k=X((u,g,{rebuild:I=!1,buyerInitiated:M=!1}={})=>{const h=d.value,F=W(t??p.value??[],v),N=Q(h,F),se=h.some(ie=>ie.method.type==="direct"),w=Ce([u],[...h,...!se&&r.value?[{method:r.value}]:[]],F,{negotiatedPaymentLines:P.value?.lines,deferredTotal:U,hasPayableDeposit:!!C.value?.amount,hasFixedSellingPlan:O.value,rebuild:I,paymentTermsTemplateType:H?.type,preserveShopPayApproval:S});g?d.value=Ee(w,g):d.value=w;const D=Q(w,F),B=Se(N,D,_);B&&(a.value=!0,m.monorailEvent(xe({uniqueToken:n.value.defaultAttributes?.uniqToken||"",shopGid:x,shopCurrencyCode:T,presentmentCurrencyCode:_,previousPaymentMethod:N,currentPaymentMethod:D})));const re=M&&Ae(N,D);(B||re)&&i({})},[a,p,P.value?.lines,r,U,C.value?.amount,_,d,m,n.value.defaultAttributes?.uniqToken,x,T,i,H,O,t,v,S]);J(()=>{oe&&!f&&d.value.length===0&&(L.current=!1)},[f]);const R=y.at(0);if(e&&!f&&!L.current&&R&&!Ie(d.value)&&!(ne&&y.length>1)){const u=K(R);c.leaveErrorBreadcrumb("rebuilding payment lines on missing selected payment line",{displayedPaymentMethods:JSON.stringify(y),selectedPaymentMethod:u}),k(u,void 0,{rebuild:!0}),L.current=!0}return E(()=>[f,k],[f,k])}function W(e,t){return t?e.filter(n=>n.type!==j.CreditCard):e}function De(e,t){return e.method.type===t.type?{...e,method:{...e.method,...t}}:e}function Ee(e,t){return e.map(n=>De(n,t))}function z(e){if(e===void 0)return"";const t="name"in e&&e.name||void 0,n="paymentMethodIdentifier"in e&&e.paymentMethodIdentifier||void 0;return ke(e.type,t,n)}function xe({uniqueToken:e,shopGid:t,shopCurrencyCode:n,presentmentCurrencyCode:a,checkoutSessionIdentifier:r,previousPaymentMethod:o,currentPaymentMethod:p}){return{schemaId:"multi_currency_checkout_payment_method_change/2.0",payload:{shopId:parseInt(Me(t),10),userToken:e,checkoutToken:r||"",shopCurrencyCode:n,checkoutPresentmentCurrencyCode:a,priorPaymentMethodHandle:z(o),priorPaymentType:Y(o?.type||""),newPaymentMethodHandle:z(p),newPaymentType:Y(p?.type||""),isPriorPaymentMethodMc:V(a,o),isNewPaymentMethodMc:V(a,p)}}}function Q(e,t){return t.find(n=>e.find(a=>"paymentMethodIdentifier"in a.method&&"paymentMethodIdentifier"in n?a.method.paymentMethodIdentifier===n.paymentMethodIdentifier:a.method.type==="wallet"&&n.type==="wallet"?a.method.name===n.name:a.method.type===n.type))}function Ke({isApplePayAvailable:e}){const{checkout:{identity:t},shopPay:n}=b(),a=Z(),r=de(e);return E(()=>Fe({identity:t,shopPay:n,negotiatedFields:a},{isApplePayAvailable:r}),[t,r,a,n])}function Ve(){const{shop:e}=b(),t=e.hasFlagEnabled(be),n=Te();return ue(()=>!t&&n.value)}function Ye(){const e=$(),{negotiate:t}=ee(),{shopPay:n,checkout:a,observability:r}=b(),o=a.configuration.addressSettings.nonBillingAddressSettings;return{updateCheckoutAddress:X(async({shippingAddress:s,billingAddress:i,fallbackPhoneNumber:P},C=!1)=>
1{if(!s&&!i)return;const l=[];if(s){l.push("shippingAddress");const m=o.value.isRequired("phone",{countryCode:s.countryCode,useMerchantSettings:!0})&&!s.phone?P:s.phone;r.log("wallets_shipping_address_update","useUpdateCheckoutAddress: update with Shop Pay vaulted address",{isPostalCodePadded:_e(s.postalCode,s.countryCode),countryCode:s.countryCode}),e.shippingAddress.value={...s,phone:m,oneTimeUse:s.oneTimeUse||!1}}if(i){l.push("billingAddress");const m=o.value.isRequired("phone",{countryCode:i.countryCode,useMerchantSettings:!0})&&!i.phone?P:i.phone;e.billingAddress.value={...i,phone:m}}const c=Ne(s??e.shippingAddress.value,i??e.billingAddress.value);n.user.hasCreditCards.value&&(c?e.billingAddressOption.value="shipping":e.billingAddressOption.value="custom"),!C&&await t({include:l,silenceViolations:["non-stock"],fieldsToResolve:l})},[t,e.shippingAddress,e.billingAddress,e.billingAddressOption,o,n.user,r])}}export{Ve as a,Ye as b,Ke as c,Je as u};
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.