import{aD as a,aE as u,aF as m}from"./app.B46ok1sD.js";import{A as c,p as d,g,i as f}from"./getCountryCallingCode.Cec8KyDv.js";const p=/[()\-._ ]+/g;class _{formatter;regionCode;countryCode;constructor(t){const e=i(t);this.regionCode=e?t:a,this.countryCode=this.getCountryCodeFromRegionCode(t),this.formatter=new c(this.regionCode)}format(t){return this.updateCountryCode(t),this.formatter.reset(),y(t,this.formatter,this.countryCode)||""}update(t){const e=i(t);this.regionCode=e?t:a,this.countryCode=this.getCountryCodeFromRegionCode(this.regionCode),this.formatter=new c(this.regionCode)}getNormalizedNumber(t){try{return d(t,this.regionCode).format("E.164")}catch{return t}}getNationalNumber(t){if(!this.regionCode||s(t).length<4)return"";try{return d(t,this.regionCode).nationalNumber||""}catch{return""}}getCountryCodeFromRegionCode(t){try{return i(t)?parseInt(g(t),10):u}catch{return u}}updateCountryCode(t){if(t.indexOf("+")===-1||s(t).length<1)return;let e;const o=h(t);if(s(t).length>10)e=o;else{const n=l(t);n&&o&&this.countryCode!==n&&(e=o)}e&&this.update(e)}}function l(r){try{const t=h(r);return t&&i(t)?parseInt(g(t),10):u}catch{return parseInt(r.split(" ")[0].replace("+",""),10)}}function y(r,t,e){let o;for(const n of r.replace(p,""))o=t.input(n);if(e===u&&o?.startsWith("+")){const[n,...C]=o.split(" ");return C.length?`${n} ${C.join("-")}`:o}return o}function h(r){try{const t=d(r);return t.country||m.get(Number(t.countryCallingCode))}catch{return a}}function i(r){return f(r)}function s(r){return r.replace(/\D/g,"")}export{_ as default};