1import{k as e,A as s,T as d,h as a,n as t,u as n,S as r,x as i,e as l,_ as o,q as c,Q as u,f as p,i as m,o as f}from"./2c1ab0fe.D_oO1jU7.js";import{bl as g,e9 as h,bJ as b,ct as A,n as v,fi as S,b as y,R as _,f9 as C,l as w,eL as D,c as P,P as I,B as M,y as N,fj as T,W as E,A as k,C as B,cS as x,fk as O,J as L,$ as V,I as z,fl as F,bB as $,cZ as j}from"./164ad2e3.DgUUtBtV.js";import{b as R}from"./efa0389a.-R9eik6_.js";import{O as q,aT as U,bb as W,eg as H,eW as J,cE as Q,ek as G,bY as Y,da as Z,eX as X,dx as K,eY as ee,d as se,k as de,eZ as ae,Q as te,e_ as ne,cp as re,bj as ie,bh as le,e$ as oe,a7 as ce,f0 as ue,f1 as pe}from"./4c290a1e.D9lE9kmU.js";import{O as me}from"./f692f62f.D8N74P4K.js";import{C as fe}from"./a422df8c.CGT3eUwi.js";import{O as ge,u as he}from"./7a8217fd.BlWFPiiA.js";import{M as be,a as Ae,u as ve}from"./b684bff6.Dv62TgX4.js";import{C as Se}from"./0e67bd3b.DkCvQkdq.js";import{u as ye,A as _e}from"./74835653.9kmD7491.js";import{P as Ce}from"./47b970b2.Bspt4mBz.js";import{u as we}from"./53bbdad9.Bipg1_Lt.js";function De({id:i,editableAddress:l,addressType:o,countriesOverride:c,saveText:u,cancelText:p,onSave:m,onSuccess:f,onCancel:C,showSavedAddressSelector:w=!0,addressErrorsSignal:D,combineViolationAndValidationErrors:P=!0,addressSettings:I,showDefaultAddressCheckbox:M=!1,onAddressAutoComplete:N}){const[T,E]=e(!1),{i18n:k,checkout:B,shopPay:x}=q(),{createAddressParts:O}=U(),L=O.addressModalState.value,V=W("shippingAddress").value,z=W("billingAddress").value,F="shipping"===o,$=B.installments.isSupported.value,j=H(),R=J(),Z=c??(F?j:R),X="billing"===o,K=$&&x.session.isInstallmentsSelected.value&&B.installments.supportedCountryOptions.value.length>0?B.installments.supportedCountryOptions.value:R,ee=X&&$&&x.session.isInstallmentsSelected.value,se=ee?K:Z,{updateCountryCodeForSPIBillingAddress:de}=ye(l.fields.countryCode,se),ae=X?B.configuration.addressSettings.billingAddressSettings.value:B.configuration.addressSettings.nonBillingAddressSettings.value,te=$?function({i18n:e,paymentMethodMustSupportInterestBearingLoans:s,supportedCountryOptions:d}){const a=d.map((e=>e.label)).join(", ");return s?a?e.translate("installments.installments_debit_cards_supported_countries",{countries:a}):e.translate("installments.installments_valid_debit_cards_fallback"):a?e.translate("installments.installments_cards_supported_countries",{countries:a}):e.translate("installments.installments_valid_cards_fallback")}({i18n:k,paymentMethodMustSupportInterestBearingLoans:B.installments.paymentMethodMustSupportInterestBearingLoans.value,supportedCountryOptions:B.installments.supportedCountryOptions.value}):"",ne=l.value,re=s({...ne}),ie=l.fields?.countryCode.value,le=I??ae,oe=g(ie,se,le),ce=h(ie),ue=d((()=>Q()),[]),pe=D??ue,me=F?G:Y,{violations:fe,clearViolations:ge}=b(me);a((()=>{("shipping"===o&&V||"billing"===o&&z)&&ge()}),[ge,o,V,z]),a((()=>{if("editing"!==L.status)return;const e=ce(o,Array.from(fe)),s=Array.from(e).filter((([e])=>ne[e]===re.current?.[e]));if(0===s.length)return;const d=oe(ne,o),a=P?s.concat(Array.from(d)):Array.from(d);t((()=>{for(const[e,s]of a)pe[e].value=s}))}),[pe,L.status,o,P,ne,oe,fe,ce]);const he=s((()=>{for(const e of Object.keys(pe))pe[e].value=void 0}));a((()=>{const e=he.current;return()=>e()}),[]),a((()=>{ee&&de()}),[ee,de]);const be=B.configuration.defaultPhoneNumber.value;a((()=>{if(!be)return;const e=le?.isRequired("phone",{useMerchantSettings:!0});e&&!l.fields.phone.value&&(l.fields.phone.value=be)}),[be,le,l.fields.phone]);const Ae=n(r,{children:[M?n(A,{id:`${i??`${o}AddressForm`}_default_address`,name:"default_address",checked:"default"===L.setAsDefault||"enabled"===L.setAsDefault,disabled:"default"===L.setAsDefault,onCh
1ange:e=>{O.addressModalState.value={...L,setAsDefault:e?"enabled":"disabled"}},label:"default"===L.setAsDefault?n(v,{color:"subdued",children:k.translate("address_management.address_form.default_address")}):k.translate("address_management.address_form.default_address")}):null,n(S,{submitText:u??k.translate("address_management.address_form.save"),cancelText:p??k.translate("address_management.address_form.cancel"),loading:T,handleCancel:C})]});return n(_,{onSubmit:async()=>{if(T)return;E(!0);const e=oe(ne,o);if(e.size)return t((()=>{for(const[s,d]of e)pe[s].value=d})),void E(!1);await(m?.(ne))&&f?.(),E(!1)},children:[ee?n(r,{children:[n(v,{children:te}),n(y,{blockSize:"base"})]}):null,n(_e,{id:i??`${o}AddressForm`,address:l,addressType:o,addressErrors:pe,showSavedAddressSelector:w,addressSettings:le,onAddressAutoComplete:N,countries:se,children:Ae})]})}function Pe({explicitlyPreferred:e,onSetDefault:s,showBadge:d=!0,badgeSize:a="base"}){const{i18n:t}=q(),i=!e&&s;return n(r,{children:[e&&d&&n(r,{children:[n(y,{blockSize:"small-400"}),"small"===a?n("span",{className:"CctLS",children:n(C,{size:"small",children:t.translate("payment.default")})}):n(C,{size:a,children:t.translate("payment.default")})]}),i&&n(w,{inlineSize:"fill",variant:"plain",onClick:s,accessibilityLabel:t.translate("shipping.address_default"),inlineAlignment:"start",textDecoration:"none",children:t.translate("shipping.address_default")})]})}function Ie({address:e,actions:d,nameLinePosition:a,addressDisplayName:t,explicitlyPreferred:c,onSetDefault:u,isImmutableAddress:p,isSelected:m,showsMoreOptionsWhenSelected:f,showPhone:g}){const{i18n:h}=q(),{nameLine:b,primary:A,secondary:S}=D({address:e,nameLinePosition:a,addressDisplayName:t,showPhone:g}),_=i(me),w=_&&Boolean(c)&&!p,{nameRef:E,probeRef:k,showProbe:B,inlineBadgeFits:x}=function({enabled:e,primary:d,isSelected:a,showsMoreOptionsWhenSelected:t}){const n=s(null),r=s(null),i=l(!1),c=l(!1);return o((()=>{c.value=e}),[e,c]),o((()=>{const s=n.current,d=r.current;if(!e||!s||!d)return;const l=()=>{const e=s.closest("label"),n=e?.parentElement,r=s.getClientRects();if(!n||1!==r.length)return void(i.value=!1);const[l]=r,o=n.getBoundingClientRect(),c=getComputedStyle(n),u="rtl"===c.direction?l.left-o.left:o.right-l.right,p=d.getBoundingClientRect().width,m=t&&!a?function(e){const s=parseFloat(getComputedStyle(document.documentElement).fontSize),d=Ne(e.getPropertyValue(Te(Z.fontSize.base)),s)*T+Ne(e.getPropertyValue(Te(Z.spacing.small100)),s);return Number.isFinite(d)?d:Me}(c):0;i.value=p>0&&u-m>=p};let o=!1;return l(),document.fonts?.ready.then((()=>{o||l()})).catch((()=>{})),window.addEventListener("resize",l),()=>{o=!0,window.removeEventListener("resize",l)}}),[e,c.value,d,a,t,i]),{nameRef:n,probeRef:r,showProbe:c,inlineBadgeFits:i}}({enabled:w,primary:A,isSelected:m,showsMoreOptionsWhenSelected:f}),O=n(r,{children:[n(y,{display:"inline",inlineSize:"small-200"}),n("span",{className:"_2x9LQ",children:n(C,{size:"small",children:h.translate("payment.default")})})]});return n(N,{gridAutoFlow:"column",gridTemplateColumns:"minmax(0, 1fr) minmax(auto, max-content)",gridTemplateRows:"minmax(0, 1fr)",gap:"base",alignItems:"start",alignContent:"start",children:[n(P,{alignItems:"start",children:n("div",{className:"bAwqP",children:["block"===a&&n(I,{children:b}),w?n(M,{children:[n("span",{ref:E,children:n(v,{type:"strong",children:A})}),B.value&&n("span",{"aria-hidden":!0,className:"Oic4c",ref:k,children:O}),x.value&&O]}):n(I,{children:n(v,{type:"strong",children:A})}),n(I,{children:S}),!p&&n(Pe,{explicitlyPreferred:c,onSetDefault:m?u:void 0,showBadge:!_||!x.value,badgeSize:_?"small":"base"})]})}),d]})}const Me=24;function Ne(e,s){const d=e.trim();return d.endsWith("rem")?X(d,s):d.endsWith("px")?parseFloat(d):NaN}function Te(e){return e.replace(/^var\(|\)$/g,"")}function Ee({state:e,description:s,error:d,onConfirm:a,onCancel:t}){const{i18n:i}=q();return n(r,{children:[d?n(P,{gap:"base",children:n(E,{tone:"critical",errorType:k.PaymentError,children:d})}):null,n(I,{children:s}),n(y,{blockSize:"base"}),n(S,{submitText:i.translate("shipping.delete"),cancelText:i.translate("address_management.address_form.cancel"),loading:"deleting"===e,handleSubmit:a,handleCancel:t,submitButtonAppearance:"critical"})]})}function ke({state:e,title:s,description:d,error:a,onConfirm:t,onCancel:r}){return n(ge,{open:"active"===e||"deleting"===e,heading:s,onHide:r,children:n(Ee,{state:e,description:d,error:a,onConfirm:t,onCancel:r})})}const Be="addressSelector--",xe=L("AddressSelector");
1function Oe({id:s,selectedId:a="",addressType:t="shipping",onChange:i,onEdit:l,onDelete:o,onSetDefault:u,addresses:p,addressesTitle:m,immutableAddresses:f=[],immutableAddressSections:g=[],getAddressDisplayName:h,selectedAddressDetails:b}){const A=B(s,xe),{i18n:S}=q(),[_,C]=e("idle"),w=x(),D=d((()=>p.filter((e=>!e.disabled))),[p]),P=d((()=>p.filter((e=>e.disabled))),[p]),I="shipping"===t,M=O(t),N=c((e=>(l||o)&&e===a),[l,o,a]),[T,E]=e(M),k=d((()=>l?{accessibilityLabel:I?S.translate("shipping.address_edit"):S.translate("billing.address_edit"),onClick:l,label:I?S.translate("shipping.edit"):S.translate("billing.edit")}:void 0),[l,I,S]),L=c((()=>(E(M),C("active"))),[M]),V=d((()=>o?{accessibilityLabel:I?S.translate("shipping.address_delete"):S.translate("billing.address_delete"),onClick:L,label:I?S.translate("shipping.delete"):S.translate("billing.delete"),destructive:!0}:void 0),[o,I,S,L]),z=a?Le(a,A):void 0,F=c((([e=""])=>{const s=function(e,s=""){return e.replace(`${s}${Be}`,"")}(e,A);s&&i(s)}),[i,A]),{ungroupedImmutableAddresses:$,groupedImmutableAddresses:j}=function(e,s){return d((()=>{const d=new Map(e.map((e=>[e.id,e]))),a=new Set(s.flatMap((({addressIds:e})=>[...e])));return{ungroupedImmutableAddresses:e.filter((({id:e})=>!a.has(e))),groupedImmutableAddresses:s.map((({title:e,addressIds:s})=>({title:e,addresses:Array.from(s).flatMap((e=>{const s=d.get(e);return s?[s]:[]}))})))}}),[e,s])}(f,g),R=p.length+f.length===1,U=I?S.translate("shipping.address_more"):S.translate("billing.address_more"),W=d((()=>[...k?[k]:[],...V?[V]:[]]),[k,V]),H=$.length>0&&p.length>0&&m,J=d((()=>z?[z]:[]),[z]);return n(r,{children:[n(fe,{name:`${t}Address`,values:J,onChange:F,hideRadioControl:R,selectedContentBackground:b?"selected":void 0,children:[n(Ve,{addresses:$,formId:A,selectedId:a,isImmutable:!0,getAddressDisplayName:h,onSetDefault:u}),H&&n(r,{children:[n(y,{blockSize:"base"}),n(v,{color:"subdued",children:m}),n(y,{blockSize:"base"})]}),n(Ve,{addresses:D,formId:A,selectedId:a,shouldShowMoreOptionsButton:N,moreOptionsAccessibilityLabel:U,moreOptionsActions:W,getAddressDisplayName:h,onSetDefault:u,selectedAddressDetails:b}),n(Ve,{addresses:P,formId:A,selectedId:a,shouldShowMoreOptionsButton:N,moreOptionsAccessibilityLabel:U,moreOptionsActions:W,getAddressDisplayName:h,onSetDefault:u}),j.map((({title:e,addresses:s})=>n(Ve,{title:e,addresses:s,formId:A,selectedId:a,isImmutable:!0,selectedAddressDetails:b},e)))]}),o&&n(ke,{state:_,title:I?S.translate("shipping.address_delete"):S.translate("billing.address_delete"),description:S.translate("address_management.confirm_address_deletion",{address:T}),onConfirm:async()=>{C("deleting"),await o(),w.current&&C("idle")},onCancel:()=>C("idle")})]})}function Le(e,s=""){return`${s}${Be}${e}`}function Ve({title:e,addresses:s,formId:d,selectedId:a,isImmutable:t=!1,shouldShowMoreOptionsButton:i,moreOptionsAccessibilityLabel:l,moreOptionsActions:o,getAddressDisplayName:c,onSetDefault:u,selectedAddressDetails:p}){const m=s.map((e=>n(ze,{addressId:e.id,address:e.address,choiceValue:Le(e.id,d),disabled:e.disabled,isImmutableAddress:t,showMoreOptionsButton:Boolean(i?.(e.id)),moreOptionsAccessibilityLabel:l,moreOptionsActions:o,addressDisplayName:c?.(e.id),explicitlyPreferred:e.default,onSetDefault:u,isSelected:a===e.id,details:a===e.id?p:void 0},e.id)));return n(r,e?{children:[n(y,{blockSize:"base"}),n(v,{color:"subdued",children:e}),n(y,{blockSize:"base"}),m]}:{children:m})}const ze=u((function({addressId:e,address:s,choiceValue:d,disabled:a=!1,isImmutableAddress:t=!1,showMoreOptionsButton:r=!1,moreOptionsAccessibilityLabel:l="",moreOptionsActions:o=[],addressDisplayName:c,explicitlyPreferred:u,onSetDefault:p,isSelected:m,details:f}){const g=i(me),h=n(R,{value:d,disabled:a,selectedContent:f,selectedContentPadding:f?"none":void 0,secondaryContent:r&&!t&&n(be,{accessibilityLabel:l,options:o}),children:n(N,{gridAutoFlow:"column",gridTemplateColumns:"minmax(0, 1fr)",gridTemplateRows:"minmax(0, 1fr)",alignItems:"center",alignContent:"center",children:n(P,{gap:"small-400",children:n(Ie,{nameLinePosition:"inline",address:s,addressDisplayName:c,explicitlyPreferred:u,isImmutableAddress:t,onSetDefault:p,isSelected:m,showsMoreOptionsWhenSelected:!t&&o.length>0,showPhone:!0})})})},e);return g?h:n(N,{gridAutoFlow:"column",gridTemplateColumns:"minmax(0, 1fr)",gridTemplateRows:"minmax(0, 1fr)",alignItems:"start",alignContent:"start",children:h},e)}));function Fe({onClick:e,textLabel:s}){const{rollup:{action:{tone:d}={}}={}}=V();
1return n(w,{tone:"custom"===d?"custom":void 0,variant:"plain",textDecoration:"none",onClick:e,children:n(P,{direction:"inline",gap:"small-100",alignItems:"center",children:[n(z,{type:"plus",size:"base"}),n(v,{children:s})]})})}function $e({open:e,isEditing:s,address:d,addressType:a,onSave:t,onClose:i,id:l,saveText:o,cancelText:c,showSavedAddressSelector:u,combineViolationAndValidationErrors:f,addressErrorsSignal:g,addressSettings:h,modalSubtitle:b,showDefaultAddressCheckbox:A,errorBannerMessage:v}){const{i18n:S}=q(),_="shipping"===a,C=_?S.translate("address_management.address_form.add"):S.translate("billing.address_form.add_address"),w=_?S.translate("shipping.address_edit"):S.translate("billing.address_edit"),D=s?w:C,M=_?S.translate("address_management.address_form.save"):S.translate("billing.address_form.save"),N=_?S.translate("address_management.address_form.cancel"):S.translate("billing.address_form.cancel"),T=void 0===f?s:f,B=p((()=>v?.value??void 0));return n(ge,{open:e,heading:D,onHide:i,children:[b?n(r,{children:[n(I,{color:"subdued",children:b}),n(y,{blockSize:"base"})]}):null,n(P,{gap:"base",children:[n(m,{when:B,children:e=>n(E,{tone:"critical",errorType:"shipping"===a?k.DeliveryError:k.PaymentError,children:n(I,{children:e})})}),d&&n(De,{id:l,editableAddress:d,addressType:a,saveText:o??M,cancelText:c??N,onSave:t,onSuccess:i,onCancel:i,showSavedAddressSelector:u,addressErrorsSignal:g,combineViolationAndValidationErrors:T,addressSettings:h,showDefaultAddressCheckbox:A})]})]})}function je({id:e,addressType:s="shipping",onSave:d,onAddAction:a,showSavedAddressSelector:t=!0,addressErrorsSignal:i,errorBannerMessage:l,showNewAddressButton:o=!0,combineViolationAndValidationErrors:c,addressSettings:u,modalSubtitle:p,showDefaultAddressCheckbox:m=!1,hideAddressModal:f=!1}){const{i18n:g}=q(),{createAddressParts:h}=U(),b=h.addressModalState.value,A="shipping"===s,v="editing"===b.status,S=b.addressType===s&&("editing"===b.status||"adding"===b.status),y=!f&&S,_=A?g.translate("shipping.add_address"):g.translate("billing.add_address");return n(r,{children:[o&&n(Fe,{onClick:a,textLabel:_}),n($e,{open:y,isEditing:v,address:b.address,addressType:s,onSave:d,onClose:()=>{l&&(l.value=void 0),h.addressModalState.value={status:"idle",addressType:s,address:b.address,setAsDefault:"default"}},id:e,showSavedAddressSelector:t,addressErrorsSignal:i,errorBannerMessage:l,combineViolationAndValidationErrors:c,addressSettings:u,modalSubtitle:p,showDefaultAddressCheckbox:m})]})}class Re extends Error{constructor(e,s){super(e),this.name="InvalidSelectedAddressError",this.groupingHash="AddressEdit::InvalidSelectedAddressError",this.name="InvalidSelectedAddressError",this.groupingHash=s}}function qe({addressType:s,addresses:a,immutableAddresses:t=[],immutableAddressSections:r=[],addressesTitle:i,selectedAddress:l,onSelectAddress:o,onCreateAddress:u=async()=>{},onUpdateAddress:p=async()=>{},onDeleteAddress:m=async()=>!1,onSetDefault:f=async()=>!1,addressErrorsSignal:g,canCreateAddress:h=!1,canUpdateAddress:b=!1,canDeleteAddress:A=!1,canSetDefaultAddress:v=!1,getAddressDisplayName:S,addressSettings:y,modalSubtitle:_,canChangeCompanyLocation:C=!1,createAddressFormId:w,errorBannerMessage:D,noticesSection:I="delivery",selectedAddressDetails:N,showNotices:T=!0,onBeforeSelectAddress:E,onBeforeCreateAddress:k,onBeforeUpdateAddress:B,onBeforeDeleteAddress:x,hideAddressModal:O=!1}){const{createAddressParts:L}=U(),{checkout:V,i18n:z,observability:j}=q(),{extendedAddressMode:R}=V.address,W="shipping"===s&&V.proposal.negotiated.fields.mustSelectProvidedAddress.value,{defaultShippingDetails:H}=V.configuration.addressSettings.nonBillingAddressSettings.value,J=H.country.code,Q=d((()=>a.map(Ue)),[a]),G=d((()=>t.map(Ue)),[t]),Y=d((()=>Q.filter((e=>!e.disabled))),[Q]),[Z,X]=e(0),ee=c((e=>{const s=[...Y,...G],d=s.find((({id:s})=>s===e));if(d)if(E){let e=!1;E(d,(()=>{e=!0,o(d)})),e||X((e=>e+1))}else o(d);else{const d=s.map((({id:e})=>e)).join(",");j.error(new Re(`Unexpected address id: '${e}' not found in choices ${d}`,"AddressEdit::handleChange::InvalidSelectedAddressError"))}}),[Y,G,o,E,j]),se=c((()=>
1{if(!l)throw new Re("Attempted to edit an address without a selected address","AddressEdit::handleEditAction::InvalidSelectedAddressError");L.addressModalState.value={status:"editing",address:K(l.address,{extendedAddressMode:R}),addressType:s,addressId:l.id,setAsDefault:l.default?"default":"disabled"}}),[l,s,L.addressModalState,R]),de=c((()=>{const e=Y?.[0],d=K({firstName:e?.address.firstName,lastName:e?.address.lastName,countryCode:J??e?.address.countryCode},{extendedAddressMode:R});L.addressModalState.value={status:"adding",address:d,addressType:s,setAsDefault:"disabled"}}),[s,Y,L.addressModalState,J,R]),ae=c((async()=>{if(!l)throw new Re("Attempted to delete an address without a selected address","AddressEdit::handleDelete::InvalidSelectedAddressError");const e=l.id;return x?x(e,(()=>m(e))):m(e)}),[m,x,l]),te=c((async e=>{const s=L.addressModalState.value,d="enabled"===s.setAsDefault;if("adding"===s.status){const s={address:e,setDefault:d};return k?k(s,(()=>u(s))):u(s)}if("editing"===s.status){const a={id:s.addressId,address:e,setDefault:d};return B?B(a,(()=>p(a))):p(a)}}),[L.addressModalState,u,p,k,B]),ne=c((async()=>{if(!l)throw new Re("Attempted to set a default address without a selected address","AddressEdit::handleSetDefault::InvalidSelectedAddressError");l.default||await f(l.id)}),[f,l]),re=A&&Y.length>1,ie=h||b,le=L.addressModalState.value,oe="editing"===le.status&&Q.some((({id:e})=>e===le.addressId)),ce=v&&("editing"!==le.status||oe);return n(P,{gap:"base",children:[T&&n(F,{section:I}),W?n($,{tone:"info",children:z.translate("address_management.must_use_address_banner")}):null,n(Oe,{id:"shipping"===s?"shippingAddressSelector":void 0,addressType:s,selectedId:l?.id,onChange:ee,onEdit:b?se:void 0,getAddressDisplayName:S,addresses:Q,addressesTitle:i,immutableAddresses:G,immutableAddressSections:r,onDelete:re?ae:void 0,onSetDefault:v?ne:void 0,selectedAddressDetails:N},Z),C&&n(M,{padding:"none small-100",children:n(Se,{showIcon:!0})}),ie&&n(M,{padding:"none small-100",children:n(je,{id:w,addressType:s,onSave:te,onAddAction:de,showNewAddressButton:h,showSavedAddressSelector:!1,addressErrorsSignal:g,errorBannerMessage:D,modalSubtitle:_,addressSettings:y,showDefaultAddressCheckbox:ce,hideAddressModal:O})})]})}function Ue(e){return{...e,id:e.id?e.id:ee(e.address)}}const We=e=>!e.firstName?.trim();function He(e,s,d,a){!function(e,s,d){const a=e.selectedPaymentMethod.value;if(!a||!de(a))return;const t=a.paymentAttributes.billingAddress.address;We(t)&&ae(t,s)&&e.selectPaymentMethod({...a,paymentAttributes:{...a.paymentAttributes,billingAddressValid:d,billingAddress:{...a.paymentAttributes.billingAddress,address:{...t,firstName:s.firstName}}}})}(e,d,a),function(e,s,d){t((()=>{for(const a of e.paymentMethods.value){if(!de(a))continue;const{billingAddress:t}=a.paymentAttributes;We(t.address)&&ae(t.address,s)&&e.updateCreditCard(a.id,{billingAddressValid:d,billingAddress:{...t,address:{...t.address,firstName:s.firstName}}})}}))}(s,d,a)}function Je({addressType:e="shipping",onPersistSuccess:s}={}){const{i18n:d,checkout:{validation:a},shopPay:t}=q(),{isMissingFirstName:r}=Ae({addressType:e}),i=te(),l=p((()=>{const s="billing"===e?t.session.selectedBillingAddress.value:t.session.selectedShippingAddress.value;return s?.id===ne?s:s?.id??("billing"===e?i.billingAddress.value:i.shippingAddress.value)})),o=a.missingFields.firstName.input,u=a.missingFields.firstName.error;(function({enabled:e,addressType:s,onPersistSuccess:d}){const{i18n:a,shopPay:t,observability:n,checkout:r}=q(),i=te(),{lastJourneyProgression:l,lastNegotiation:o}=ce(),c=r.validation.missingFields.firstName.input,u=r.validation.missingFields.firstName.error,p="billing"===s?ue:pe;function m(e){const s=e.peek();if(!("violations"in s))return;const d=s.violations.filter((e=>!p.has(e.code)));d.length!==s.violations.length&&(e.value={...s,violations:d})}function f(){u.value="",("billing"===s?r.addressManager.billing.value:r.addressManager.shipping.value).errors.fields.firstName.value=void 0,m(l),m(
1o)}function g(e){const s=t.session.selectedBillingAddress.value;s&&s.id===e.id&&ae(s.address,e.address)&&(t.session.unstable_updateSelectedBillingAddress(e),i.billingAddress.value=e.address)}he("firstName",(async()=>{if(!e)return{success:!0};const l=c.value.trim();if(!l)return u.value=a.translate("field_errors.address_first_name_blank"),{success:!1,location:"first_name_blank"};const o=function(e,s,d,a){return"billing"===e?d?s.find((e=>se(e.address,d,["phone","firstName"])))??null:null:a??null}(s,t.user.addresses.value,i.billingAddress.value,t.session.selectedShippingAddress.value);return o?t.user.addresses.value.some((e=>e.id===o.id))?async function(e,s,l){const o="billing"===l,c=o?r.addressManager.billing.value:r.addressManager.shipping.value,p={...e,address:{...e.address,firstName:s}},m=await c.updateAddress({id:e.id,address:p.address}),h=t.user.addresses.value.find((s=>s.id===e.id))??p;return m?(o?(i.billingAddress.value=m.address,He(t.session,t.user,h.address,h.valid)):(g(h),He(t.session,t.user,h.address,h.valid)),f(),d?.(),{success:!0}):(n.leaveErrorBreadcrumb("Shop Pay update address first name failed"),u.value=a.translate("field_errors.address_generic_error"),{success:!1,location:"first_name_update_failed"})}(o,l,s):function(e,a){const n={...e,address:{...e.address,firstName:a}};return"billing"===s?(t.session.unstable_updateSelectedBillingAddress(n),i.billingAddress.value=n.address):(t.session.unstable_updateSelectedShippingAddress(n),i.shippingAddress.value=n.address,g(n)),f(),d?.(),{success:!0}}(o,l):"billing"===s?function(e){const s=i.billingAddress.value;if(!s)return{success:!1,location:"first_name_no_address"};const a={...s,firstName:e};return i.billingAddress.value=a,f(),d?.(),{success:!0}}(l):{success:!1,location:"first_name_no_address"}}))})({enabled:r,addressType:e,onPersistSuccess:s}),f((()=>{if(l.value)return()=>{o.value="",u.value=""}}));const m=c((e=>{if(!re(e))return d.translate("field_errors.address_first_name_blank")}),[d]),g=ie(o,u,m);le(o,u,m);const h=u.value,b=oe(h)?h.message:h;return n(j,{name:"firstName",label:d.translate("contact.first_name_label"),required:!0,autocomplete:"given-name",...g,error:g.error||b})}function Qe(e,s,d){return re(e)?d(e,s)?{isValid:!0}:{isValid:!1,reason:"phone_invalid"}:{isValid:!1,reason:"phone_blank"}}const Ge={id:"fb48dec1806e3e11b7375d723d9e47d5006dda9d3285b2f42dc9138fade9163b",type:"mutation",name:"AddPhone",source:"mutation AddPhone($phone:String!,$payAddressUuid:String){addPhone(phone:$phone,payAddressUuid:$payAddressUuid){userErrors{field message __typename}__typename}}"};function Ye({addressType:e="shipping"}={}){const{i18n:s,checkout:{validation:t}}=q(),r=te(),{validatePhoneNumber:i}=we(),{isMissingPhone:l}=ve({addressType:e}),o="billing"===e?r.billingAddress.value:r.shippingAddress.value,u=o?.countryCode,p=t.missingFields.phone.input,m=t.missingFields.phone.error,g=t.missingFields.phone.isValid;(function(e,s,{enabled:a,addressType:t="shipping"}){const{i18n:n,graphql:{shopPayGraphql:r},shopPay:i,observability:l}=q(),o=te(),{formatPhoneNumber:c,validatePhoneNumber:u}=we(),p="billing"===t?o.billingAddress.value:o.shippingAddress.value,m=p?.countryCode,f=d((()=>function({graphql:e,observability:s}){return async(d,a)=>{const{data:t,error:n}=await e.mutate(Ge,{variables:{phone:d,payAddressUuid:a}});return n||null==t||null==t.addPhone?(s.leaveErrorBreadcrumb("Shop Pay add phone mutation failed with a transport or null-response error"),!1):!(t.addPhone.userErrors?.length>0&&(s.leaveErrorBreadcrumb("Shop Pay add phone mutation returned user errors",{userErrors:JSON.stringify(t.addPhone.userErrors)}),1))}}({graphql:r,observability:l})),[r,l]);he("phone",(async()=>{if(!a)return{success:!0};const d=Qe(s.value,m,u);if(!d.isValid)return e.value=function(e,s){return"phone_blank"===e?s.translate("field_errors.phone_blank"):s.translate("field_errors.shipping_line_phone_invalid")}(d.reason,n),{success:!1,location:d.reason};e.value=void 0;const r=c(s.value,m);if(!r)return e.value=n.translate("field_errors.shipping_line_phone_invalid"),{success:!1,location:"phone_format_failed"};const l="billing"===t?i.session.selectedBillingAddress.value?.uuid:i.session.selectedShippingAddress.value?.uuid;return await f(r,l)?(i.user.unstable_setPhoneNumber(r),{success:!0}):(e.value=n.translate("field_errors.shipping_line_phone_invalid"),{success:!1,location:"add_phone_mutation_failed"})}))})(m,p,{enabled:l,addressType:e}),f((()=>{const e=Qe(p.value,u,i);g.value=e.isValid})),a((()=>()=>{g.value=!0,m.value=""}),[g,m]);const h=c((e=>re(e)?i(e??"",u)?void 0:s.translate("field_errors.shipping_line_phone_invalid"):s.translate("field_errors.phone_blank")),[i,u,s]),{onInput:b,...A}=ie(p,m,h);le(p,m,h);const v=m.value,S=oe(v)?v.message:v;return n(Ce,{name:"phone",countryCode:u??"",label:s.translate("contact.phone_label"),prefillCountryCode:!0,required:!0,autocomplete:"billing"===e?"billing tel-national":"shipping tel-national",...A,onInput:e=>{b?.(e),p.value=e??""},error:A.error||S})}function Ze({addressType:e="shipping",onFirstNamePersisted:s}={}){const{isMissingPhone:d}=ve({addressType:e}),{isMissingFirstName:a}=Ae({addressType:e});return d||a?n(M,{paddingInline:"base",paddingBlockStart:"small-200",paddingBlockEnd:"base",children:n(P,{direction:"block",gap:"base",children:[a&&n(Je,{addressType:e,onPersistSuccess:s}),d&&n(Ye,{addressType:e})]})}):null}export{qe as A,De as C,Ze as M,Fe as a,ke as b,Oe as c,Ie as d};
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.