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