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/hooks/usePasswordValidationRules.ts
var usePasswordValidationRules_exports = {};
__export(usePasswordValidationRules_exports, {
  default: () => usePasswordValidationRules_default,
  usePasswordValidationRules: () => usePasswordValidationRules
});
module.exports = __toCommonJS(usePasswordValidationRules_exports);
var import_react = require("react");
var DEFAULT_MESSAGES = {
  required: "Password is required",
  minLength: "Password must be at least {length} characters long",
  requireUppercase: "at least one uppercase letter",
  requireLowercase: "at least one lowercase letter",
  requireNumber: "at least one number",
  requireSpecialCharacters: "at least one special character",
  summary: "Password must contain: {requirements}"
};
var formatMessage = (template, variables) => Object.keys(variables).reduce(
  (message, key) => message.replace(
    new RegExp(`{${key}}`, "g"),
    String(variables[key] ?? "")
  ),
  template
);
var resolveMessage = (key, translate, messageKeys) => {
  const messageKey = messageKeys == null ? void 0 : messageKeys[key];
  if (messageKey && translate) {
    const translated = translate(messageKey);
    if (translated) {
      return translated;
    }
  }
  return DEFAULT_MESSAGES[key];
};
var usePasswordValidationRules = (passwordRules, options) => {
  const translate = options == null ? void 0 : options.translate;
  const messageKeys = options == null ? void 0 : options.messageKeys;
  const fallbackMinLength = options == null ? void 0 : options.fallbackMinLength;
  return (0, import_react.useMemo)(() => {
    const rules = [
      {
        required: true,
        message: resolveMessage("required", translate, messageKeys)
      }
    ];
    const effectiveRules = {
      ...passwordRules
    };
    if (effectiveRules.minLength == null && fallbackMinLength) {
      effectiveRules.minLength = fallbackMinLength;
    }
    if (effectiveRules.minLength) {
      const rawMessage = resolveMessage("minLength", translate, messageKeys);
      rules.push({
        min: effectiveRules.minLength,
        message: formatMessage(rawMessage, { length: effectiveRules.minLength })
      });
    }
    if (effectiveRules.requireUppercase || effectiveRules.requireLowercase || effectiveRules.requireNumber || effectiveRules.requireSpecialCharacters) {
      rules.push({
        validator: (_rule, value) => {
          if (!value) {
            return Promise.resolve();
          }
          const requirements = [];
          if (effectiveRules.requireUppercase && !/[A-Z]/.test(value)) {
            requirements.push(
              resolveMessage("requireUppercase", translate, messageKeys)
            );
          }
          if (effectiveRules.requireLowercase && !/[a-z]/.test(value)) {
            requirements.push(
              resolveMessage("requireLowercase", translate, messageKeys)
            );
          }
          if (effectiveRules.requireNumber && !/\d/.test(value)) {
            requirements.push(
              resolveMessage("requireNumber", translate, messageKeys)
            );
          }
          if (effectiveRules.requireSpecialCharacters && !/[!@#$%^&*]/.test(value)) {
            requirements.push(
              resolveMessage("requireSpecialCharacters", translate, messageKeys)
            );
          }
          if (requirements.length > 0) {
            const template = resolveMessage("summary", translate, messageKeys);
            return Promise.reject(
              new Error(
                formatMessage(template, {
                  requirements: requirements.join(", ")
                })
              )
            );
          }
          return Promise.resolve();
        }
      });
    }
    return rules;
  }, [
    fallbackMinLength,
    messageKeys == null ? void 0 : messageKeys.requireLowercase,
    messageKeys == null ? void 0 : messageKeys.requireNumber,
    messageKeys == null ? void 0 : messageKeys.requireSpecialCharacters,
    messageKeys == null ? void 0 : messageKeys.requireUppercase,
    messageKeys == null ? void 0 : messageKeys.minLength,
    messageKeys == null ? void 0 : messageKeys.required,
    messageKeys == null ? void 0 : messageKeys.summary,
    passwordRules == null ? void 0 : passwordRules.minLength,
    passwordRules == null ? void 0 : passwordRules.requireLowercase,
    passwordRules == null ? void 0 : passwordRules.requireNumber,
    passwordRules == null ? void 0 : passwordRules.requireSpecialCharacters,
    passwordRules == null ? void 0 : passwordRules.requireUppercase,
    translate
  ]);
};
var usePasswordValidationRules_default = usePasswordValidationRules;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  usePasswordValidationRules
});
