1import{A as K,h as J,T as N,q as $,l as de,f as ue}from"./esnext-vendor.BBoIVOQW.js";import{bV as le,aq as ce,a5 as j,bW as pe,bX as ye,T as M,bY as me,W as Q,bZ as he,V as ee,b_ as Pe,b$ as ve,c0 as W,c1 as fe,c2 as Ce,c3 as ge,c4 as Se,c5 as Ae,c6 as be,c7 as Y,I as Me,c8 as Te,c9 as _e,aU as Le}from"./addresses-is-address-empty.ZJ1ThpFy.js";import{f as te,c as ke,bA as G,bB as Fe}from"./hydrate.Tsur0pib.js";import{h as Ie}from"./hooks-useShopPayExternalAppContext.YLtTu3k6.js";import{s as Ee,i as we}from"./helpers-derivations.f29j39ws.js";class De extends Error{constructor(){super(...arguments),this.name="UnsupportedShopPayCustomerCardError"}}function Je({allowPreselect:e=!0,displayedPaymentMethods:t}={}){const n=le(),{hasNegotiatedAlternativePaymentCurrencySignal:a,newCardSignal:r}=ce(),o=j(),p=o.paymentMethods,{value:s}=pe(),{negotiate:i}=te(),P=o.paymentLines,g=ye(),{checkout:{identity:l},observability:c,userEvents:m,shop:O}=M(),{currencyCode:T,id:U,paymentMethodAutoSelectionDisabled:ne}=O,v=l.current.value==="shopPay",S=!v&&O.hasFlagEnabled(me),y=z(t??s,v),{value:ae}=o.buyerIdentity,d=Q().paymentLines,{value:H}=o.deferredTotal,{value:x}=o.paymentFlexibilityPaymentTermsTemplate,R=he(),_=ae?.presentmentCurrency||T,oe=ke(),L=K(!1),q=K(!1),A=v?d.value.find(u=>u.method.type===ee.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 De("Shop Pay proposed payment line contains an unsupported Customer Account saved card"),{severity:"warning",metadata:{value:{paymentMethodType:A}}}))},[c,A]);const f=N(()=>{const u=y.find(Pe);if(S&&u&&ve(d.value))return W(u);const C=d.value.filter(h=>fe(h,y,{identity:l})||Ce(h)),F=ge(C),[b]=F;return b!==void 0?b:(c.leaveErrorBreadcrumb("Unexpected: Selected payment method is empty because `paymentLines` array is empty",{displayedPaymentMethods:JSON.stringify(y),displayedProposedPaymentLines:JSON.stringify(C)}),"")},[y,l,c,d.value,S]),k=$((u,C,{rebuild:F=!1,buyerInitiated:b=!1}={})=>{const h=d.value,I=z(t??p.value??[],v),E=Z(h,I),se=h.some(ie=>ie.method.type==="direct"),w=Se([u],[...h,...!se&&r.value?[{method:r.value}]:[]],I,{negotiatedPaymentLines:P.value?.lines,deferredTotal:H,hasPayableDeposit:!!g.value?.amount,hasFixedSellingPlan:R.value,rebuild:F,paymentTermsTemplateType:x?.type,preserveShopPayApproval:S});C?d.value=Oe(w,C):d.value=w;const D=Z(w,I),V=Ae(E,D,_);V&&(a.value=!0,m.monorailEvent(Ue({uniqueToken:n.value.defaultAttributes?.uniqToken||"",shopGid:U,shopCurrencyCode:T,presentmentCurrencyCode:_,previousPaymentMethod:E,currentPaymentMethod:D})));const re=b&&be(E,D);(V||re)&&i({})},[a,p,P.value?.lines,r,H,g.value?.amount,_,d,m,n.value.defaultAttributes?.uniqToken,U,T,i,x,R,t,v,S]);J(()=>{oe&&!f&&d.value.length===0&&(L.current=!1)},[f]);const B=y.at(0);if(e&&!f&&!L.current&&B&&!Ie(d.value)&&!(ne&&y.length>1)){const u=W(B);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 N(()=>[f,k],[f,k])}function z(e,t){return t?e.filter(n=>n.type!==ee.CreditCard):e}function Ne(e,t){return e.method.type===t.type?{...e,method:{...e.method,...t}}:e}function Oe(e,t){return e.map(n=>Ne(n,t))}function X(e){if(e===void 0)return"";const t="name"in e&&e.name||void 0,n="paymentMethodIdentifier"in e&&e.paymentMethodIdentifier||void 0;return Fe(e.type,t,n)}function Ue({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:X(o),priorPaymentType:G(o?.type||""),newPaymentMethodHandle:X(p),newPaymentType:G(p?.type||""),isPriorPaymentMethodMc:Y(a,o),isNewPaymentMethodMc:Y(a,p)}}}function Z(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 We({isApplePayAvailable:e}){const{checkout:{identity:t},shopPay:n}=M(),a=j(),r=de(e);return N(()=>Ee({identity:t,shopPay:n,negotiatedFields:a},{isApplePayAvailable:r}),[t,r,a,n])}function Ye(){const{shop:e}=M(),t=e.hasFlagEnabled(Te),n=_e();return ue(()=>!t&&n.value)}function Ge(){const e=Q(),{negotiate:t}=te(),{shopPay:n,checkout:a,observability:r}=M(),o=a.configuration.addressSettings.nonBillingAddressSettings;return{updateCheckoutAddress:$(async({shippingAddress:s,billingAddress:i,fallbackPhoneNumber:P},g=!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:Le(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=we(s??e.shippingAddress.value,i??e.billingAddress.value);n.user.hasCreditCards.value&&(c?e.billingAddressOption.value="shipping":e.billingAddressOption.value="custom"),!g&&await t({include:l,silenceViolations:["non-stock"],fieldsToResolve:l})},[t,e.shippingAddress,e.billingAddress,e.billingAddressOption,o,n.user,r])}}export{Ye as a,Ge as b,We 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.