import { t as n } from "./accelbyte-widgets58.mjs";
import { FeUtils as m } from "./accelbyte-widgets45.mjs";
import { zxcvbn as g, zxcvbnOptions as w } from "@zxcvbn-ts/core";
import i from "classnames";
import { passwordGraph as S } from "./accelbyte-widgets453.mjs";
import { unsafePassword as f } from "./accelbyte-widgets454.mjs";
import r from "react";
import { z as v } from "zod";
import y from "./accelbyte-widgets455.mjs";
import { InputGroup as P } from "./accelbyte-widgets229.mjs";
import c from "./accelbyte-widgets456.mjs";
const E = 100, a = v.enum(["veryWeak", "weak", "fair", "strong", "veryStrong"]);
class B extends r.Component {
  constructor(s) {
    super(s), this.getStrengthLevelBasedOnScore = (t) => {
      switch (t) {
        case 0:
          return a.enum.veryWeak;
        case 1:
          return a.enum.weak;
        case 2:
          return a.enum.fair;
        case 3:
          return a.enum.strong;
        case 4:
          return a.enum.veryStrong;
        default:
          return a.enum.veryWeak;
      }
    }, this.calculatePasswordStrength = (t) => {
      if (!t)
        return this.setState({ passwordStrengthScore: null });
      const { score: e } = g(t);
      this.setState({ passwordStrengthScore: e });
    }, this.debounceCalculatePasswordStrength = m.debounce(this.calculatePasswordStrength, E), this.togglePassword = () => {
      this.setState({ showPassword: !this.state.showPassword });
    }, this.renderStrengthMeter = () => {
      const { hasStrengthMeter: t, passwordStrengthMeterDataQa: e } = this.props, { passwordStrengthScore: l } = this.state, o = this.getStrengthLevelBasedOnScore(l);
      if (!(!t || l === null))
        return /* @__PURE__ */ r.createElement("div", { className: c.passwordStrengthMeter }, /* @__PURE__ */ r.createElement("div", { className: i("strengthMeterBar", o), "data-qa-id": e == null ? void 0 : e.bars }, a.options.map((u, d) => /* @__PURE__ */ r.createElement("div", { key: `bar-${u}`, className: i("bar", { fill: d <= l }) }))), /* @__PURE__ */ r.createElement("span", { className: "text-xs text-[color:rgb(var(--od-rgb-text),0.65)]" }, n("password.strength.label")), /* @__PURE__ */ r.createElement("span", { className: i("strengthMeterLevel", o), "data-qa-id": e == null ? void 0 : e.strengthText }, b(o)));
    }, this.state = {
      showPassword: s.isPasswordVisibleByDefault || !1,
      passwordStrengthScore: null
    };
  }
  componentDidMount() {
    const s = {
      dictionary: {
        password: f
      },
      graphs: S
    };
    w.setOptions(s);
  }
  componentDidUpdate(s) {
    const { hasStrengthMeter: t, value: e } = this.props;
    t && typeof e == "string" && (e !== s.value || t !== s.hasStrengthMeter) && this.debounceCalculatePasswordStrength(e);
  }
  render() {
    const { showPassword: s } = this.state, {
      togglePassword: t,
      className: e,
      type: l,
      hasStrengthMeter: o,
      isPasswordVisibleByDefault: u,
      passwordStrengthMeterDataQa: d,
      ...p
    } = this.props;
    return /* @__PURE__ */ r.createElement(r.Fragment, null, /* @__PURE__ */ r.createElement(
      P,
      {
        className: i(c.inputGroupPassword, e),
        ...p,
        type: s ? "text" : "password",
        afterElement: t && /* @__PURE__ */ r.createElement("span", { className: c.eyeIconContainer, onClick: this.togglePassword }, /* @__PURE__ */ r.createElement(y, { open: s })) || null
      }
    ), o && this.renderStrengthMeter());
  }
}
function b(h) {
  switch (h) {
    case "fair":
      return n("password.strength.level.fair");
    case "strong":
      return n("password.strength.level.strong");
    case "veryStrong":
      return n("password.strength.level.veryStrong");
    case "veryWeak":
      return n("password.strength.level.veryWeak");
    case "weak":
      return n("password.strength.level.weak");
    default:
      return "";
  }
}
export {
  B as InputGroupPassword,
  a as PASSWORD_STRENGTH_METER
};
