1import{g as e,h as t,T as n,q as a,s as r,k as s}from"./2c1ab0fe.XVnTovwp.js";import{aI as o,a as i,bG as d,bH as u,aF as p,E as l,bI as c,aG as y,bJ as m,bK as h,bL as v,bM as f,bN as g,bO as b,bP as P,bQ as C,p as M,J as A,bR as k,au as T,b9 as S}from"./f67abd2c.DYpmk7mw.js";import{r as _,c7 as I,c8 as w,c9 as E}from"./164ad2e3.hrg71Gqs.js";import{h as N}from"./e12db40c.D-IRYT_x.js";import{s as q,i as x}from"./08a3b809.D2TiFyOY.js";class F extends Error{constructor(){super(...arguments),this.name="UnsupportedShopPayCustomerCardError"}}function L({allowPreselect:r=!0,displayedPaymentMethods:s}={}){const A=o(),{checkout:{identity:k,negotiator:T},observability:S,userEvents:E,shop:q}=i(),{hasNegotiatedAlternativePaymentCurrencySignal:x,newCardSignal:L}=T.context,U=T.current.fields.paymentMethods,{value:B}=d(),{negotiate:G}=_(),R=T.current.fields.paymentLines,H=u(),{currencyCode:D,id:V,paymentMethodAutoSelectionDisabled:K}=q,Q="shopPay"===k.current.value,z=!Q,W=O(s??B,Q),{value:X}=T.current.fields.buyerIdentity,Y=T.parts.paymentLines,{value:Z}=T.current.fields.deferredTotal,{value:$}=T.current.fields.paymentFlexibilityPaymentTermsTemplate,ee=p(),te=X?.presentmentCurrency||D,ne=I(),ae=e(!1),re=e(!1),se=Q?Y.value.find(e=>e.method.type===l.CreditCard)?.method.type:void 0;t(()=>{se&&!re.current&&(re.current=!0,S.counter({name:"shop_pay_unsupported_customer_card_on_payline",value:1,attributes:{payment_method_type:se}}),S.error(new F("Shop Pay proposed payment line contains an unsupported Customer Account saved card"),{severity:"warning",metadata:{value:{paymentMethodType:se}}}))},[S,se]);const oe=n(()=>{const e=W.find(c);if(z&&e&&y(Y.value))return m(e);const t=Y.value.filter(e=>h(e,W,{identity:k})||v(e)),n=f(t),[a]=n;return void 0!==a?a:(S.leaveErrorBreadcrumb("Unexpected: Selected payment method is empty because `paymentLines` array is empty",{displayedPaymentMethods:JSON.stringify(W),displayedProposedPaymentLines:JSON.stringify(t)}),"")},[W,k,S,Y.value,z]),ie=a((e,t,{rebuild:n=!1,buyerInitiated:a=!1}={})=>{const r=Y.value,o=O(s??U.value??[],Q),i=J(r,o),d=r.some(e=>"direct"===e.method.type),u=g([e],[...r,...!d&&L.value?[{method:L.value}]:[]],o,{negotiatedPaymentLines:R.value?.lines,deferredTotal:Z,hasPayableDeposit:Boolean(H.value?.amount),hasFixedSellingPlan:ee.value,rebuild:n,paymentTermsTemplateType:$?.type,preserveShopPayApproval:z});Y.value=t?function(e,t){return e.map(e=>function(e,t){return e.method.type===t.type?{...e,method:{...e.method,...t}}:e}(e,t))}(u,t):u;const p=J(u,o),l=b(i,p,te);l&&(x.value=!0,E.monorailEvent(function({uniqueToken:e,shopGid:t,shopCurrencyCode:n,presentmentCurrencyCode:a,checkoutSessionIdentifier:r,previousPaymentMethod:s,currentPaymentMethod:o}){return{schemaId:"multi_currency_checkout_payment_method_change/2.0",payload:{shopId:parseInt(M(t),10),userToken:e,checkoutToken:r||"",shopCurrencyCode:n,checkoutPresentmentCurrencyCode:a,priorPaymentMethodHandle:j(s),priorPaymentType:w(s?.type||""),newPaymentMethodHandle:j(o),newPaymentType:w(o?.type||""),isPriorPaymentMethodMc:C(a,s),isNewPaymentMethodMc:C(a,o)}}}({uniqueToken:A.value.defaultAttributes?.uniqToken||"",shopGid:V,shopCurrencyCode:D,presentmentCurrencyCode:te,previousPaymentMethod:i,currentPaymentMethod:p})));const c=a&&P(i,p);(l||c)&&G({})},[x,U,R.value?.lines,L,Z,H.value?.amount,te,Y,E,A.value.defaultAttributes?.uniqToken,V,D,G,$,ee,s,Q,z]);t(()=>{ne&&!oe&&0===Y.value.length&&(ae.current=!1)},[oe]);const de=W.at(0);if(r&&!oe&&!ae.current&&de&&!N(Y.value)&&!(K&&W.length>1)){const e=m(de);S.leaveErrorBreadcrumb("rebuilding payment lines on missing selected payment line",{displayedPaymentMethods:JSON.stringify(W),selectedPaymentMethod:e}),ie(e,void 0,{rebuild:!0}),ae.current=!0}return n(()=>[oe,ie],[oe,ie])}function O(e,t){return t?e.filter(e=>e.type!==l.CreditCard):e}function j(e){if(void 0===e)return"";const t="name"in e&&e.name||void 0,n="paymentMethodIdentifier"in e&&e.paymentMethodIdentifier||void 0;return E(e.type,t,n)}function J(e,t){return t.find(t=>e.find(e=>"paymentMethodIdentifier"in e.method&&"paymentMethodIdentifier"in t?e.method.paymentMethodIdentifier===t.paymentMethodIdentifier:"wallet"===e.method.type&&"wallet"===t.type?e.method.name===t.name:e.method.type===t.type))}function U({isApplePayAvailable:e}){const{checkout:{identity:t,negotiator:a},shopPay:s}=i(),o=r(e);return n(()=>q({identity:t,shopPay:s,negotiatedFields:a.current.fields},{isApplePayAvailable:o}),[t,o,a.current.fields,s])}function B(){const{shop:e}=i(),t=e.hasFlagEnabled(A),n=k();return s(()=>!t&&n.value)}function G(){const{negotiate:e}=_(),{shopPay:t,checkout:n,observability:r}=i(),s=n.configuration.addressSettings.nonBillingAddressSettings;return{updateCheckoutAddress:a(async({shippingAddress:a,billingAddress:o,fallbackPhoneNumber:i},d=!1)=>
1{if(!a&&!o)return;const u=[];if(a){u.push("shippingAddress");const e=s.value.isRequired("phone",{countryCode:a.countryCode,useMerchantSettings:!0})&&!a.phone?i:a.phone;r.log("wallets_shipping_address_update","useUpdateCheckoutAddress: update with Shop Pay vaulted address",{isPostalCodePadded:T(a.postalCode,a.countryCode),countryCode:a.countryCode}),n.negotiator.parts.shippingAddress.value={...a,phone:e,oneTimeUse:a.oneTimeUse||!1}}if(o){u.push("billingAddress");const e=s.value.isRequired("phone",{countryCode:o.countryCode,useMerchantSettings:!0})&&!o.phone?i:o.phone;n.negotiator.parts.billingAddress.value={...o,phone:e}}const p=x(a??n.negotiator.parts.shippingAddress.value,o??n.negotiator.parts.billingAddress.value);t.user.hasCreditCards.value&&(n.negotiator.parts.billingAddressOption.value=p?"shipping":"custom"),d||await e({legacyFiltering:{include:u,silenceViolations:["non-stock"]},silenceViolations:["non-stock",...S],fieldsToResolve:u})},[e,n.negotiator.parts.shippingAddress,n.negotiator.parts.billingAddress,n.negotiator.parts.billingAddressOption,s,t.user,r])}}export{B as a,G as b,U as c,L 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.