import{lM as P,lb as p,dy as _,aZ as S,dx as m,aw as v,k0 as g,aA as E,j$ as b,m1 as O,m2 as M}from"./getNormalizedPaymentMethodName.2fnRWc01.js";import{C as T}from"./esnext-vendor.25PjUpIY.js";import{a as w,f as B}from"./helpers-installmentsNotSupportedForAddress.DNoB_2j0.js";const U=Date.parse("2026-02-24T00:00:00.000Z");function F(e){return e?f(e.consent.analytics)||f(e.consent.marketing):!1}function R(e){return{analytics:e?.consent.analytics.consented===!0,marketing:e?.consent.marketing.consented===!0}}function f(e){return e.consented!=null&&e.isExpired!==!0&&H(e.providedAt)}function H(e){if(e==null)return!1;const s=Date.parse(e);return!Number.isNaN(s)&&s>=U}function V({consentManager:e,shop:s,shopPayEssentialEventer:r,source:d},{shopAccountUuid:o,userPrivacySettings:t,experiments:l}){if(t&&s.hasFlagEnabled(P)&&e.setPrefetchedConsent(t),o===""||d.type==="shopPayExternal")return;const u=F(t),a=[p.variants.treatment_a,p.variants.treatment_b,p.variants.treatment_c,p.variants.treatment_d].some(n=>l.includes(`${p.handle}=${n}`)),h=(t?.consent.displayBanner??e.shouldShowBanner.value)&&a&&!u?"visible":"hidden";r.send("shop_pay_essential_payment_page_ready/1.0",{variant:h,checkout_token:d.checkoutSessionIdentifier??"",shop_account_uuid:o,event_timestamp:Date.now()})}function N(e){return!e.hasFlagEnabled(b)}function k(e){return typeof e=="boolean"?e:e.value}function Y(e,{isApplePayAvailable:s}){const{identity:r,shop:d,shopPay:o,negotiatedFields:t}=e;return T(()=>{const l=t.paymentMethods.value??[];return B(l,{identity:r,installmentsSelected:!1,isApplePayAvailable:k(s),isUsdcEnabled:N(d),idealEnabled:E({managedByMarketsPro:t.managedByMarketsPro.value}),isBareCardOnly:!1,isShopAppLayout:g(o.app.config),shopAppVersion:o.app.config.version})})}function K(e,{negotiatedPaymentMethods:s,isApplePayAvailable:r}){const d=O(e,s);return M(d,e,s,{isApplePayAvailable:r})}function $({proposal:e,checkout:s,shopPay:r,observability:d,shippingAddress:o,billingAddress:t,fallbackPhoneNumber:l,buyerAddresses:u}){if(!o&&!t)return;const a=e.proposed,c=e.negotiated.fields,h=_({canUpdateDeliveryAddress:c.canUpdateDeliveryAddress.value,mustSelectProvidedAddress:c.mustSelectProvidedAddress.value,proposedAddress:a.shippingAddress.value,buyerAddresses:u}),n=o&&h?o:void 0,i=t;if(!n&&!i)return;const y=s.configuration.addressSettings.nonBillingAddressSettings.value;if(n){const C=y.isRequired("phone",{countryCode:n.countryCode,useMerchantSettings:!0})&&!n.phone?l:n.phone;d.log("wallets_shipping_address_update","shop-pay pre-hydration: update with Shop Pay vaulted address",{isPostalCodePadded:S(n.postalCode,n.countryCode),countryCode:n.countryCode}),a.shippingAddress.value={...n,phone:C,oneTimeUse:n.oneTimeUse||!1}}if(i){const C=y.isRequired("phone",{countryCode:i.countryCode,useMerchantSettings:!0})&&!i.phone?l:i.phone;a.billingAddress.value={...i,phone:C}}n&&m(a.shippingAddress),i&&m(a.billingAddress);const A=w(n??a.shippingAddress.value,i??a.billingAddress.value);r.user.paymentMethods.value.some(v)&&(a.billingAddressOption.value=A?"shipping":"custom")}export{$ as a,K as b,R as c,F as h,V as r,Y as s};
