import{It as e,Jt as t,Pt as n,Xt as a,zt as o}from"./630ba094.L_X-5TXi.js";import{hw as s,jf as r,rS as i,tg as l,wy as c,xO as u}from"./6ec9a0fa.rdcQt2v8.js";import{n as v}from"./c7b92b97.keF148le.js";function d(){const{checkout:{negotiator:e,proposal:t}}=u(),{acceptSmsMarketing:n,phone:o,smsMarketingPhone:s,shippingAddress:r}=e.parts,i=r.fields.phone.value,l=s.value,c=0===(t.negotiated.fields.availableDeliveryAddresses.value??[]).length?i:"",v=l||o.value||c||"";return{handleSmsMarketingConsent:a(t=>{s.value="",n.value=t,t?s.value=v:e.negotiate({withResultHandling:!0,silenceViolations:["all"]})},[n,v,e,s])}}function p(){const{checkout:{negotiator:e}}=u(),{shippingAddress:t,locationAddress:a}=e.parts;return n(()=>{const e=t.value,n=a.value;return r(e,n)})}function g(){const{validatePhoneNumber:n}=v(),a=p(),{i18n:s,checkout:{wallets:r,negotiator:i}}=u(),{smsMarketingPhone:l}=i.parts,{marketingPhoneInputError:c}=i.context,d=t(!1);e(()=>{const e=l.value,t=a.value,u=c.peek();if(!d.current)return void(d.current=!0);const v=n(e,t??"ZZ")?void 0:o(()=>s.translate("field_errors.address_phone_blank"));v?u||(c.value=v):c.value=void 0,v||r.activeSession.value||o(()=>{i.negotiate({withResultHandling:!0,silenceViolations:["all"]})})})}var h=new Set(["BUYER_IDENTITY_MARKETING_CONSENT_PHONE_NUMBER_DOES_NOT_MATCH_EXPECTED_PATTERN"]);function f(e,n,a){const{checkout:{wallets:o,negotiator:r}}=u(),{smsMarketingPhone:v,acceptSmsMarketing:d}=r.parts,{marketingPhoneInputError:p}=r.context,g=t();function f(){void 0!==g.current&&g.current===v.peek()&&(p.value=void 0,g.current=void 0)}return l(t=>{if("success"===t.type)return void f();if("error"!==t.type)return;let n=!1;for(const a of t.violations){if("UnprocessableTermViolation"!==a.__typename||!h.has(a.code)||!c(a.target))continue;n=!0;const t=e||(a.localizedMessage??a.nonLocalizedMessage);p.value=t,g.current=v.peek()}n||f()}),i(v,p,void 0,{reason:s.InvalidOptInPhone,field:n,owner:a,shouldSkip:()=>Boolean(o.activeSession.value)||!d.value})}export{d as i,g as n,p as r,f as t};