{"version":3,"file":"format-phone-number.cjs","names":[],"sources":["../../../../src/components/PhoneInput/format-phone-number/format-phone-number.ts"],"sourcesContent":["import type { PhoneInputCountryData } from '../phone-data';\n\nexport function getMaskDigitCount(format: string): number {\n  let count = 0;\n  for (let i = 0; i < format.length; i++) {\n    if (format[i] === '.') {\n      count++;\n    }\n  }\n  return count;\n}\n\nexport function formatPhoneNumber(rawValue: string, country: PhoneInputCountryData): string {\n  if (!rawValue) {\n    return '';\n  }\n\n  const digits = rawValue.replace(/\\D/g, '');\n  if (!digits) {\n    return '';\n  }\n\n  const { dialCode, format } = country;\n\n  if (!digits.startsWith(dialCode)) {\n    return `+${digits}`;\n  }\n\n  const nationalDigits = digits.slice(dialCode.length);\n  const maxDigits = getMaskDigitCount(format);\n  const clampedDigits = nationalDigits.slice(0, maxDigits);\n\n  let result = '';\n  let digitIndex = 0;\n\n  for (let i = 0; i < format.length; i++) {\n    if (digitIndex >= clampedDigits.length) {\n      break;\n    }\n\n    if (format[i] === '.') {\n      result += clampedDigits[digitIndex];\n      digitIndex++;\n    } else {\n      result += format[i];\n    }\n  }\n\n  return `+${dialCode} ${result}`;\n}\n\nexport function clampToMask(rawValue: string, country: PhoneInputCountryData | null): string {\n  const digits = rawValue.replace(/\\D/g, '');\n  if (!digits) {\n    return '';\n  }\n  if (!country) {\n    return `+${digits}`;\n  }\n  const { dialCode, format } = country;\n  const maxNational = getMaskDigitCount(format);\n  if (digits.startsWith(dialCode)) {\n    const clamped = digits.slice(dialCode.length).slice(0, maxNational);\n    return `+${dialCode}${clamped}`;\n  }\n  return `+${digits}`;\n}\n"],"mappings":";;AAEA,SAAgB,kBAAkB,QAAwB;CACxD,IAAI,QAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KACjC,IAAI,OAAO,OAAO,KAChB;CAGJ,OAAO;AACT;AAEA,SAAgB,kBAAkB,UAAkB,SAAwC;CAC1F,IAAI,CAAC,UACH,OAAO;CAGT,MAAM,SAAS,SAAS,QAAQ,OAAO,EAAE;CACzC,IAAI,CAAC,QACH,OAAO;CAGT,MAAM,EAAE,UAAU,WAAW;CAE7B,IAAI,CAAC,OAAO,WAAW,QAAQ,GAC7B,OAAO,IAAI;CAGb,MAAM,iBAAiB,OAAO,MAAM,SAAS,MAAM;CACnD,MAAM,YAAY,kBAAkB,MAAM;CAC1C,MAAM,gBAAgB,eAAe,MAAM,GAAG,SAAS;CAEvD,IAAI,SAAS;CACb,IAAI,aAAa;CAEjB,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;EACtC,IAAI,cAAc,cAAc,QAC9B;EAGF,IAAI,OAAO,OAAO,KAAK;GACrB,UAAU,cAAc;GACxB;EACF,OACE,UAAU,OAAO;CAErB;CAEA,OAAO,IAAI,SAAS,GAAG;AACzB;AAEA,SAAgB,YAAY,UAAkB,SAA+C;CAC3F,MAAM,SAAS,SAAS,QAAQ,OAAO,EAAE;CACzC,IAAI,CAAC,QACH,OAAO;CAET,IAAI,CAAC,SACH,OAAO,IAAI;CAEb,MAAM,EAAE,UAAU,WAAW;CAC7B,MAAM,cAAc,kBAAkB,MAAM;CAC5C,IAAI,OAAO,WAAW,QAAQ,GAE5B,OAAO,IAAI,WADK,OAAO,MAAM,SAAS,MAAM,CAAC,CAAC,MAAM,GAAG,WAC3B;CAE9B,OAAO,IAAI;AACb"}