const PHONE_MIN_DIGITS = 7;
const PHONE_MAX_DIGITS = 15;
const DIGIT_PATTERN = /\d+/g;
const PHONE_ALLOWED_CHARACTERS = /^[+\d\s\-().]+$/;
function extractPhoneDigits(value) {
  if (typeof value !== "string") return "";
  const matches = value.match(DIGIT_PATTERN);
  return matches ? matches.join("") : "";
}
function validatePhoneNumber(value) {
  if (typeof value !== "string") {
    return { valid: true, normalized: null, digits: "", reason: null };
  }
  const normalized = value.trim();
  if (!normalized) {
    return { valid: true, normalized: null, digits: "", reason: null };
  }
  const digits = extractPhoneDigits(normalized);
  if (!normalized.startsWith("+")) {
    return { valid: false, normalized, digits, reason: "missing_country_code" };
  }
  if (!PHONE_ALLOWED_CHARACTERS.test(normalized)) {
    return { valid: false, normalized, digits, reason: "invalid_characters" };
  }
  const plusCount = (normalized.match(/\+/g) ?? []).length;
  if (plusCount !== 1) {
    return { valid: false, normalized, digits, reason: "invalid_plus_sign" };
  }
  if (digits.length < PHONE_MIN_DIGITS) {
    return { valid: false, normalized, digits, reason: "too_short" };
  }
  if (digits.length > PHONE_MAX_DIGITS) {
    return { valid: false, normalized, digits, reason: "too_long" };
  }
  return { valid: true, normalized, digits, reason: null };
}
function isValidPhoneNumber(value) {
  return validatePhoneNumber(value).valid;
}
export {
  PHONE_MAX_DIGITS,
  PHONE_MIN_DIGITS,
  extractPhoneDigits,
  isValidPhoneNumber,
  validatePhoneNumber
};
//# sourceMappingURL=phone.js.map
