import { E as compilerRuntimeExports, j as jsxRuntimeExports } from "./vendor-react-DYNCg6N5.js";
import { L as List, am as ThemeIcon, r as rem } from "./vendor-mantine-h0WlM2Mj.js";
import { Y as IconCircleDashed, Z as IconCircleCheck, $ as IconCircleDashedX } from "./vendor-icons-xWhXK_Ui.js";
import { c as allowedPasswordCharactersString } from "./passwordUtils-B3CN2t6O.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
const RulesConditionList = (t0) => {
  const $ = compilerRuntimeExports.c(7);
  const {
    rules,
    check
  } = t0;
  const getIndicator = _temp;
  let t1;
  if ($[0] !== check || $[1] !== rules) {
    let t22;
    if ($[3] !== check) {
      t22 = (rule, index) => /* @__PURE__ */ jsxRuntimeExports.jsx(List.Item, { icon: /* @__PURE__ */ jsxRuntimeExports.jsx(ThemeIcon, { color: getIndicator(rule.condition, check).color, size: 24, radius: "xl", children: getIndicator(rule.condition, check).icon }), children: rule.label }, index);
      $[3] = check;
      $[4] = t22;
    } else {
      t22 = $[4];
    }
    t1 = rules.map(t22);
    $[0] = check;
    $[1] = rules;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  let t2;
  if ($[5] !== t1) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(List, { spacing: "xs", size: "sm", mb: 20, center: true, children: t1 });
    $[5] = t1;
    $[6] = t2;
  } else {
    t2 = $[6];
  }
  return t2;
};
function _temp(condition, isCheck) {
  if (!isCheck) {
    return {
      icon: /* @__PURE__ */ jsxRuntimeExports.jsx(IconCircleDashed, { style: {
        width: rem(16),
        height: rem(16)
      } }),
      color: "blue"
    };
  }
  if (condition) {
    return {
      icon: /* @__PURE__ */ jsxRuntimeExports.jsx(IconCircleCheck, { style: {
        width: rem(16),
        height: rem(16)
      } }),
      color: "teal"
    };
  }
  return {
    icon: /* @__PURE__ */ jsxRuntimeExports.jsx(IconCircleDashedX, { style: {
      width: rem(16),
      height: rem(16)
    } }),
    color: "red"
  };
}
const escapeForRegex = (str) => {
  return str.replace(/[-\\[\]^]/g, "\\$&");
};
const generatePasswordRules = (password, options, maxLengthPassword = 30, t) => {
  if (!options || typeof t !== "function") return [];
  const escapedAllowedChars = escapeForRegex(allowedPasswordCharactersString);
  const allowedCharClass = `a-zA-Z0-9${escapedAllowedChars}`;
  const rules = [options.MinLength !== void 0 && {
    condition: password.length >= (options.MinLength || 8) && password.length <= maxLengthPassword,
    label: t("register.passwordLong", {
      MinLength: options.MinLength || 8,
      MaxLength: maxLengthPassword
    }),
    shortLabel: t("register.passwordLongShort", {
      MinLength: options.MinLength || 8,
      MaxLength: maxLengthPassword
    })
  }, options.UseLowLetter && {
    condition: /[a-z]/.test(password),
    label: t("register.passwordLetters"),
    shortLabel: t("register.passwordLettersShort")
  }, options.UseDigital && {
    condition: /[0-9]/.test(password),
    label: t("register.passwordNumbers"),
    shortLabel: t("register.passwordNumbersShort")
  }, options.UseCapitalLetters && {
    condition: /[A-Z]/.test(password),
    label: t("register.passwordUppercase"),
    shortLabel: t("register.passwordUppercaseShort")
  }, options.UseSpecialCharacters && {
    condition: options.UseAllowedSpecialCharacters ? new RegExp(`[${escapedAllowedChars}]`).test(password) : /[^a-zA-Z0-9]/.test(password),
    // любой не-буквенно-цифровой
    label: t("register.passwordSpecialChars"),
    shortLabel: t("register.passwordSpecialCharsShort")
  }, options.UseAllowedSpecialCharacters && {
    condition: (() => {
      const allowedRegex = new RegExp(`[${escapedAllowedChars}]`);
      const disallowedRegex = new RegExp(`[^${allowedCharClass}]`);
      return allowedRegex.test(password) && !disallowedRegex.test(password);
    })(),
    label: t("register.allowedSpecialChars", {
      characters: allowedPasswordCharactersString
    }),
    shortLabel: t("register.allowedSpecialCharsShort", {
      characters: allowedPasswordCharactersString
    })
  }, options.UseLatin && {
    condition: /^[\x20-\x7E]*$/.test(password),
    label: t("register.passwordLatinOnly"),
    shortLabel: t("register.passwordLatinOnlyShort")
  }];
  return rules.filter(Boolean);
};
const useGenerateRules = (password, options, t0) => {
  const $ = compilerRuntimeExports.c(5);
  const maxLengthPassword = 30;
  const {
    t
  } = useTranslation();
  let t1;
  if ($[0] !== maxLengthPassword || $[1] !== options || $[2] !== password || $[3] !== t) {
    t1 = generatePasswordRules(password, options, maxLengthPassword, t);
    $[0] = maxLengthPassword;
    $[1] = options;
    $[2] = password;
    $[3] = t;
    $[4] = t1;
  } else {
    t1 = $[4];
  }
  return t1;
};
const generateMailServerPasswordRules = (password, rules, t) => {
  const result = [];
  result.push({
    condition: password.length >= rules.MinLength && password.length <= rules.MaxLength,
    label: t("register.passwordLong", {
      MinLength: rules.MinLength,
      MaxLength: rules.MaxLength
    }),
    shortLabel: t("register.passwordLongShort", {
      MinLength: rules.MinLength,
      MaxLength: rules.MaxLength
    })
  });
  if (rules.ForbidWhitespace) {
    result.push({
      condition: !/\s/.test(password),
      label: t("register.noWhitespace"),
      shortLabel: t("register.noWhitespaceShort")
    });
  }
  if (rules.RequireUppercase) {
    result.push({
      condition: /[A-Z]/.test(password),
      label: t("register.passwordUppercase"),
      shortLabel: t("register.passwordUppercaseShort")
    });
  }
  if (rules.RequireLowercase) {
    result.push({
      condition: /[a-z]/.test(password),
      label: t("register.passwordLetters"),
      shortLabel: t("register.passwordLettersShort")
    });
  }
  if (rules.RequireDigit) {
    result.push({
      condition: /\d/.test(password),
      label: t("register.passwordNumbers"),
      shortLabel: t("register.passwordNumbersShort")
    });
  }
  if (rules.AllowedSpecialCharacters !== null && rules.AllowedSpecialCharacters !== void 0) {
    const escaped = escapeForRegex(rules.AllowedSpecialCharacters);
    result.push({
      condition: password.length > 0 && !new RegExp(`[^a-zA-Z0-9${escaped}]`).test(password),
      label: t("register.allowedSpecialChars", {
        characters: rules.AllowedSpecialCharacters
      }),
      shortLabel: t("register.allowedSpecialCharsShort", {
        characters: rules.AllowedSpecialCharacters
      })
    });
  }
  if (rules.ForbiddenSpecialCharacters !== null && rules.ForbiddenSpecialCharacters !== void 0) {
    const escaped = escapeForRegex(rules.ForbiddenSpecialCharacters);
    result.push({
      condition: !new RegExp(`[${escaped}]`).test(password),
      label: t("register.forbiddenSpecialChars", {
        characters: rules.ForbiddenSpecialCharacters
      }),
      shortLabel: t("register.forbiddenSpecialCharsShort", {
        characters: rules.ForbiddenSpecialCharacters
      })
    });
  }
  return result;
};
const useGenerateMailServerRules = (password, rules) => {
  const $ = compilerRuntimeExports.c(5);
  const {
    t
  } = useTranslation();
  if (!rules) {
    let t02;
    if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
      t02 = [];
      $[0] = t02;
    } else {
      t02 = $[0];
    }
    return t02;
  }
  let t0;
  if ($[1] !== password || $[2] !== rules || $[3] !== t) {
    t0 = generateMailServerPasswordRules(password, rules, t);
    $[1] = password;
    $[2] = rules;
    $[3] = t;
    $[4] = t0;
  } else {
    t0 = $[4];
  }
  return t0;
};
const defaultMailServerPasswordOptions = {
  MinLength: 8,
  UseDigital: true,
  UseCapitalLetters: true,
  UseLatin: true,
  UseLowLetter: true,
  UseAllowedSpecialCharacters: true,
  UseSpecialCharacters: true
};
export {
  RulesConditionList as R,
  useGenerateMailServerRules as a,
  defaultMailServerPasswordOptions as d,
  useGenerateRules as u
};
//# sourceMappingURL=passwordOptions-b-kjbiiT.js.map
