var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/pro/keyboards/phoneKeyboard/utils.ts
var utils_exports = {};
__export(utils_exports, {
  formatPhoneDisplay: () => formatPhoneDisplay
});
module.exports = __toCommonJS(utils_exports);
var normalizeCallingCode = (countryCallingCode) => `${countryCallingCode || ""}`.replace(/\D/g, "");
var normalizePhoneValue = (value) => `${value || ""}`.replace(/\D/g, "");
var joinGroups = (groups, separator) => groups.filter(Boolean).join(separator === "dash" ? "-" : " ");
var splitByGroups = (phone, groups) => {
  const result = [];
  let start = 0;
  groups.forEach((size) => {
    if (start >= phone.length) return;
    result.push(phone.slice(start, start + size));
    start += size;
  });
  if (start < phone.length) {
    result.push(phone.slice(start));
  }
  return result;
};
var formatByGroups = (phone, groups, separator) => joinGroups(splitByGroups(phone, groups), separator);
var formatWithOptionalLeadingZero = (phone, withZeroGroups, withoutZeroGroups, separator) => {
  return formatByGroups(
    phone,
    phone.startsWith("0") ? withZeroGroups : withoutZeroGroups,
    separator
  );
};
var formatPhoneDisplay = (phone, countryCallingCode, separator = "space") => {
  const normalizedPhone = normalizePhoneValue(phone);
  const normalizedCode = normalizeCallingCode(countryCallingCode);
  if (!normalizedPhone) {
    return "";
  }
  switch (normalizedCode) {
    case "61":
      return formatWithOptionalLeadingZero(
        normalizedPhone,
        [2, 4, 4],
        [1, 4, 4],
        separator
      );
    case "86":
      return formatByGroups(normalizedPhone, [3, 4, 4], separator);
    case "852":
    case "853":
    case "65":
      return formatByGroups(normalizedPhone, [4, 4], separator);
    case "886":
      return formatWithOptionalLeadingZero(
        normalizedPhone,
        [4, 3, 3],
        [3, 3, 3],
        separator
      );
    case "1":
      return formatByGroups(normalizedPhone, [3, 3, 4], separator);
    case "44":
      return formatWithOptionalLeadingZero(
        normalizedPhone,
        [4, 3, 4],
        [4, 3, 3],
        separator
      );
    case "81":
      return formatWithOptionalLeadingZero(
        normalizedPhone,
        [3, 4, 4],
        [2, 4, 4],
        separator
      );
    case "82":
      return formatByGroups(normalizedPhone, [3, 3, 4], separator);
    case "60":
      return formatByGroups(normalizedPhone, [2, 4, 4], separator);
    case "66":
    case "84":
    case "351":
      return formatByGroups(normalizedPhone, [3, 3, 3], separator);
    case "63":
    case "91":
      return formatByGroups(normalizedPhone, [3, 3, 4], separator);
    case "62":
      return formatByGroups(normalizedPhone, [3, 4, 4], separator);
    default:
      return formatByGroups(normalizedPhone, [3, 3, 3, 3, 3], separator);
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  formatPhoneDisplay
});
