1import{T as e,g as t,h as n,q as a,s as r,k as s}from"./2c1ab0fe.Bywc2Brn.js";import{aO as o,c as i,bM as d,bN as u,aL as p,K as l,bO as c,aM as y,bP as m,bQ as h,bR as v,bS as f,bT as g,bU as b,bV as P,bW as C,v as M,Q as A,bX as T,a as k,bf as S}from"./9dba8418.nSn06qNc.js";import{v as _,c8 as w,c9 as I,ca as E}from"./164ad2e3.Bn4mVc0u.js";import{h as N}from"./e12db40c.xtsrYBcz.js";import{s as O,i as q}from"./08a3b809.C4g4QpSr.js";class x extends Error{constructor(){super(...arguments),this.name="UnsupportedShopPayCustomerCardError"}}function L({allowPreselect:r=!0,displayedPaymentMethods:s}={}){const A=o(),{checkout:{identity:T,negotiator:k},observability:S,userEvents:E,shop:O}=i(),{hasNegotiatedAlternativePaymentCurrencySignal:q,newCardSignal:L}=k.context,F=k.current.fields.paymentMethods,{value:R}=d(),{negotiate:J}=_(),D=k.current.fields.paymentLines,G=u(),{currencyCode:H,id:Q,paymentMethodAutoSelectionDisabled:V}=O,K="shopPay"===T.current.value,W=!K,X=s??R,z=e(()=>U(X,K),[X,K]),{value:Y}=k.current.fields.buyerIdentity,Z=k.parts.paymentLines,{value:$}=k.current.fields.deferredTotal,{value:ee}=k.current.fields.paymentFlexibilityPaymentTermsTemplate,te=p(),ne=Y?.presentmentCurrency||H,ae=w(),re=t(!1),se=t(!1),oe=K?Z.value.find(e=>e.method.type===l.CreditCard)?.method.type:void 0;n(()=>{oe&&!se.current&&(se.current=!0,S.counter({name:"shop_pay_unsupported_customer_card_on_payline",value:1,attributes:{payment_method_type:oe}}),S.error(new x("Shop Pay proposed payment line contains an unsupported Customer Account saved card"),{severity:"warning",metadata:{value:{paymentMethodType:oe}}}))},[S,oe]);const ie=e(()=>{const e=z.find(c);if(W&&e&&y(Z.value))return m(e);const t=Z.value.filter(e=>h(e,z,{identity:T})||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(z),displayedProposedPaymentLines:JSON.stringify(t)}),"")},[z,T,S,Z.value,W]),de=a((e,t,{rebuild:n=!1,buyerInitiated:a=!1}={})=>{const r=Z.value,o=U(s??F.value??[],K),i=B(r,o),d=r.some(e=>"direct"===e.method.type),u=g([e],[...r,...!d&&L.value?[{method:L.value}]:[]],o,{negotiatedPaymentLines:D.value?.lines,deferredTotal:$,hasPayableDeposit:Boolean(G.value?.amount),hasFixedSellingPlan:te.value,rebuild:n,paymentTermsTemplateType:ee?.type,preserveShopPayApproval:W});Z.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=B(u,o),l=b(i,p,ne);l&&(q.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:I(s?.type||""),newPaymentMethodHandle:j(o),newPaymentType:I(o?.type||""),isPriorPaymentMethodMc:C(a,s),isNewPaymentMethodMc:C(a,o)}}}({uniqueToken:A.value.defaultAttributes?.uniqToken||"",shopGid:Q,shopCurrencyCode:H,presentmentCurrencyCode:ne,previousPaymentMethod:i,currentPaymentMethod:p})));const c=a&&P(i,p);(l||c)&&J({})},[q,F,D.value?.lines,L,$,G.value?.amount,ne,Z,E,A.value.defaultAttributes?.uniqToken,Q,H,J,ee,te,s,K,W]);n(()=>{ae&&!ie&&0===Z.value.length&&(re.current=!1)},[ie]);const ue=z.at(0);if(r&&!ie&&!re.current&&ue&&!N(Z.value)&&!(V&&z.length>1)){const e=m(ue);S.leaveErrorBreadcrumb("rebuilding payment lines on missing selected payment line",{displayedPaymentMethods:JSON.stringify(z),selectedPaymentMethod:e}),de(e,void 0,{rebuild:!0}),re.current=!0}return e(()=>[ie,de],[ie,de])}function U(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 B(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 F({isApplePayAvailable:t}){const{checkout:{identity:n,negotiator:a},shopPay:s}=i(),o=r(t);return e(()=>O({identity:n,shopPay:s,negotiatedFields:a.current.fields},{isApplePayAvailable:o}),[n,o,a.current.fields,s])}function R(){const{shop:e}=i(),t=e.hasFlagEnabled(A),n=T();return s(()=>!t&&n.value)}function J(){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:k(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=q(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({silenceViolations:["non-stock",...S],fieldsToResolve:u})},[e,n.negotiator.parts.shippingAddress,n.negotiator.parts.billingAddress,n.negotiator.parts.billingAddressOption,s,t.user,r])}}export{R as a,J as b,F 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.