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/Login2.0/components/phoneValidation.ts
var phoneValidation_exports = {};
__export(phoneValidation_exports, {
  createPhoneValidationRules: () => createPhoneValidationRules,
  validatePhoneNumber: () => validatePhoneNumber
});
module.exports = __toCommonJS(phoneValidation_exports);
var validatePhoneNumber = async (value, getText) => {
  if (!value) {
    throw new Error(getText("pisell-phone-validation-required"));
  }
  let phone;
  let countryCode;
  if (typeof value === "string") {
    if (!value.startsWith("+")) {
      throw new Error(getText("pisell-phone-validation-invalid"));
    }
    const match = value.match(/^\+(\d{1,4})(\d+)$/);
    if (!match) {
      throw new Error(getText("pisell-phone-validation-invalid"));
    }
    countryCode = match[1];
    phone = match[2];
  } else {
    phone = value.phone;
    countryCode = value.country_calling_code;
  }
  if (!phone || !countryCode) {
    throw new Error(getText("pisell-phone-validation-required"));
  }
  switch (countryCode) {
    case "86":
      if (!/^1[3-9]\d{9}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-china"));
      }
      break;
    case "852":
      if (!/^[5-9]\d{7}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-hongkong"));
      }
      break;
    case "853":
      if (!/^6\d{7}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-macau"));
      }
      break;
    case "886":
      if (!/^9\d{8}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-taiwan"));
      }
      break;
    case "1":
      const usCanadaReg = /^[2-9]\d{2}[2-9]\d{6}$/;
      if (!usCanadaReg.test(phone)) {
        throw new Error(getText("pisell-phone-validation-us-canada"));
      }
      break;
    case "44":
      if (!/^7\d{9}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-uk"));
      }
      break;
    case "61":
      const auReg = /^0?[2-578]\d{8}$/;
      if (!auReg.test(phone)) {
        throw new Error(getText("pisell-phone-validation-australia"));
      }
      break;
    case "81":
      if (!/^[789]0\d{8}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-japan"));
      }
      break;
    case "82":
      if (!/^1[0-9]\d{7,8}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-korea"));
      }
      break;
    case "65":
      if (!/^[89]\d{7}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-singapore"));
      }
      break;
    case "60":
      if (!/^1[0-9]\d{7,8}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-malaysia"));
      }
      break;
    case "66":
      if (!/^[689]\d{8}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-thailand"));
      }
      break;
    case "84":
      if (!/^[3579]\d{8}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-vietnam"));
      }
      break;
    case "63":
      if (!/^9\d{9}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-philippines"));
      }
      break;
    case "62":
      if (!/^8\d{8,11}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-indonesia"));
      }
      break;
    case "91":
      if (!/^[6-9]\d{9}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-india"));
      }
      break;
    default:
      if (!/^\d{6,15}$/.test(phone)) {
        throw new Error(getText("pisell-phone-validation-invalid"));
      }
      break;
  }
};
var createPhoneValidationRules = (getText, required = true) => {
  const rules = [];
  rules.push({
    validator: (_, value) => {
      if (!value && !required) {
        return Promise.resolve();
      }
      return validatePhoneNumber(value, getText);
    }
  });
  return rules;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createPhoneValidationRules,
  validatePhoneNumber
});
