import '@das-fed/ui/packages/business-components/change-pwd/style.css';
import { ref as R, reactive as F, defineComponent as T, createBlock as v, openBlock as y, unref as r, isRef as $, withCtx as g, createElementVNode as z, createVNode as h, createCommentVNode as I, createTextVNode as V, toDisplayString as D } from "vue";
import { withInstall as B } from "@das-fed/utils/with-install/index";
import { t as s, i18n as x, setI18nRule as O } from "@das-fed/web/packages/i18n/index";
import { DasDialog as Z } from "@das-fed/ui/packages/components/dialog/index";
import { DasFormRef as W, DasForm as G } from "@das-fed/ui/packages/components/form/index";
import { DasFormItem as q } from "@das-fed/ui/packages/components/form-item/index";
import { DasButton as U } from "@das-fed/ui/packages/components/button/index";
import { DasMessage as K } from "@das-fed/ui/packages/components/message/index";
import { enterpriseright as M, superadminPortal as Y, systemConfiguration as j } from "@das-fed/utils/api-services/modules";
import { encryption as k } from "@das-fed/utils/atob";
const S = M.get("/user/change-pwd", (n) => (n.ignoreErrorMessage = !0, n)), A = M.put("/user/change-pwd", (n) => (n.csrf = !0, n)), H = Y.put("/change-pwd"), J = j.get("/visitor/login/with-default"), Q = (n, f) => {
  const w = R(!1), m = W(), d = R({
    prePwd: "",
    pwd: "",
    confirmPwd: ""
  }), t = F({
    pwdStrongLimit: !1,
    // 是否开启密码强度校验
    pwdRequireLength: !1,
    // 是否校验长度
    pwdMinLength: 0,
    // 最小密码长度
    pwdRequireNum: !1,
    // 密码要求包含数字
    pwdRequireLowercaseLetters: !1,
    // 密码要求包含小写字母
    pwdRequireUppercaseLetters: !1,
    // 密码要求包含大写字母
    pwdRequireSpecialCharacter: !1
    // 密码要求特殊字符
  }), L = async () => {
    const [o, e] = await J().run();
    o || (t.pwdStrongLimit = e.pwdStrongLimit, t.pwdRequireLength = e.pwdRequireLength, t.pwdMinLength = e.pwdMinLength, t.pwdRequireNum = e.pwdRequireNum, t.pwdRequireLowercaseLetters = e.pwdRequireLowercaseLetters, t.pwdRequireUppercaseLetters = e.pwdRequireUppercaseLetters, t.pwdRequireSpecialCharacter = e.pwdRequireSpecialCharacter);
  }, l = (o) => {
    let e = "";
    return t.pwdStrongLimit ? e = E(o) : e = u(o), e;
  }, _ = (o, e, a) => {
    var i;
    if (!e) return a(new Error(s("新密码不能为空")));
    if (n.mainApp === "enterpriseadmin") {
      const C = l(e);
      if ((i = m.value) == null || i.validateField("confirmPwd", () => null), C) return a(new Error(C));
    }
    a();
  }, N = (o, e, a) => {
    if (!e) return a(new Error(s("确认密码不能为空")));
    if (d.value.pwd !== e) return a(new Error(s("与新密码不一致")));
    if (n.mainApp === "enterpriseadmin") {
      const i = l(e);
      if (i) return a(new Error(i));
    }
    a();
  }, P = R({
    prePwd: [
      {
        required: !n.forceUpdate,
        message: s("旧密码不能为空"),
        trigger: "blur"
      }
    ],
    pwd: [{ validator: _, trigger: "blur" }],
    confirmPwd: [{ validator: N, trigger: "blur" }]
  }), c = R(""), b = (o) => {
    n.mainApp === "enterpriseadmin" && L(), w.value = !0, c.value = o || "";
  }, p = (o = !1) => {
    var e;
    d.value.prePwd = "", d.value.pwd = "", d.value.confirmPwd = "", (e = m.value) == null || e.resetField(), w.value = !1, o || f("onCancel");
  }, u = (o) => {
    const e = s("das-ui-business-components-change-pwd-passwordFormatRule");
    return /^(?=.*[a-zA-Z])(?=.*[\d])(?=.*[\w])[a-zA-Z\d\W_]{8,20}$/.test(o) ? "" : e;
  }, E = (o) => {
    let e = "", a = !1;
    e += s("das-ui-business-components-change-pwd-limit-number", t.pwdMinLength);
    const i = `\\S{${t.pwdMinLength},}`;
    return new RegExp(i).test(o) || (a = !0), (t.pwdRequireNum || t.pwdRequireLowercaseLetters || t.pwdRequireUppercaseLetters || t.pwdRequireSpecialCharacter) && (e += s("必须包含")), t.pwdRequireNum && (e += s("数字，"), /\d+/.test(o) || (a = !0)), t.pwdRequireLowercaseLetters && (e += s("小写字母，"), /[a-z]+/.test(o) || (a = !0)), t.pwdRequireUppercaseLetters && (e += s("大写字母，"), /[A-Z]+/.test(o) || (a = !0)), t.pwdRequireSpecialCharacter && (e += s("符号，"), /[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~]+/.test(o) || (a = !0)), a ? e.slice(0, -1) : "";
  };
  return {
    visible: w,
    formData: d,
    form: m,
    rules: P,
    openDialog: b,
    onCancel: p,
    onConfirm: async () => {
      var o;
      (o = m.value) == null || o.validate(async (e) => {
        if (e) {
          const a = {
            pwd: k(d.value.pwd),
            confirmPwd: k(d.value.confirmPwd)
          };
          if (n.mainApp === "enterpriseadmin" && n.forceUpdate) {
            let i = {};
            c.value && (i = { headers: { Authorization: c.value } }), await S({}, i).run();
            const [C] = await A({}, i).run(a);
            if (C) return;
          } else if (a.prePwd = k(d.value.prePwd), n.mainApp === "enterpriseadmin") {
            await S().run();
            const [i] = await A().run(a);
            if (i) return;
          } else {
            const [i] = await H().run(a);
            if (i) return;
          }
          p(!0), K.success(s("修改密码成功！")), f("onConfirm");
        }
      });
    }
  };
}, X = { class: "dialog-content" }, ee = {
  name: "ChangePwd"
}, re = /* @__PURE__ */ T({
  ...ee,
  props: {
    mainApp: { default: "enterpriseadmin" },
    forceUpdate: { type: Boolean }
  },
  emits: ["onCancel", "onConfirm"],
  setup(n, { expose: f, emit: w }) {
    const m = n, d = w, { visible: t, form: L, formData: l, rules: _, openDialog: N, onCancel: P, onConfirm: c } = Q(m, d);
    return f({
      openDialog: N
    }), (b, p) => (y(), v(r(Z), {
      title: r(s)("修改密码"),
      width: "460px",
      height: "360px",
      bodyStyle: { padding: 0 },
      modelValue: r(t),
      "onUpdate:modelValue": p[3] || (p[3] = (u) => $(t) ? t.value = u : null),
      "before-close": r(P)
    }, {
      footer: g(() => [
        z("div", null, [
          h(r(U), {
            size: "middle",
            style: { "margin-right": "12px" },
            onClick: r(P)
          }, {
            default: g(() => [
              V(
                D(r(x)("取消").value),
                1
                /* TEXT */
              )
            ]),
            _: 1
            /* STABLE */
          }, 8, ["onClick"]),
          h(r(U), {
            btnType: "primary",
            size: "middle",
            onClick: r(c)
          }, {
            default: g(() => [
              V(
                D(r(x)("确定").value),
                1
                /* TEXT */
              )
            ]),
            _: 1
            /* STABLE */
          }, 8, ["onClick"])
        ])
      ]),
      default: g(() => [
        z("div", X, [
          h(r(G), {
            ref_key: "form",
            ref: L,
            rules: r(_),
            style: { "overflow-x": "hidden !important" }
          }, {
            default: g(() => [
              b.forceUpdate ? I("v-if", !0) : (y(), v(r(q), {
                key: 0,
                type: "password",
                isTitle: !1,
                autocomplete: "new-password",
                "show-password": "",
                prop: "prePwd",
                label: r(s)("旧密码"),
                modelValue: r(l).prePwd,
                "onUpdate:modelValue": p[0] || (p[0] = (u) => r(l).prePwd = u),
                modelModifiers: { trim: !0 },
                maxlength: 20,
                required: ""
              }, null, 8, ["label", "modelValue"])),
              h(r(q), {
                type: "password",
                isTitle: !1,
                autocomplete: "new-password",
                "show-password": "",
                prop: "pwd",
                label: r(s)("新密码"),
                modelValue: r(l).pwd,
                "onUpdate:modelValue": p[1] || (p[1] = (u) => r(l).pwd = u),
                modelModifiers: { trim: !0 },
                maxlength: 20,
                required: ""
              }, null, 8, ["label", "modelValue"]),
              h(r(q), {
                type: "password",
                isTitle: !1,
                autocomplete: "new-password",
                "show-password": "",
                prop: "confirmPwd",
                label: r(s)("确认新密码"),
                modelValue: r(l).confirmPwd,
                "onUpdate:modelValue": p[2] || (p[2] = (u) => r(l).confirmPwd = u),
                modelModifiers: { trim: !0 },
                maxlength: 20,
                required: ""
              }, null, 8, ["label", "modelValue"])
            ]),
            _: 1
            /* STABLE */
          }, 8, ["rules"])
        ])
      ]),
      _: 1
      /* STABLE */
    }, 8, ["title", "modelValue", "before-close"]));
  }
}), te = (n, f) => {
  const w = n.__vccOpts || n;
  for (const [m, d] of f)
    w[m] = d;
  return w;
}, oe = /* @__PURE__ */ te(re, [["__scopeId", "data-v-901c1af6"]]), ae = {
  新密码不能为空: { "zh-CN": "新密码不能为空", en: "New password cannot be empty", _appCode: "framework" },
  确认密码不能为空: { "zh-CN": "确认密码不能为空", en: "Confirm password cannot be empty", _appCode: "framework" },
  与新密码不一致: { "zh-CN": "与新密码不一致", en: "Doesn't match the new password", _appCode: "framework" },
  旧密码不能为空: { "zh-CN": "旧密码不能为空", en: "Old password cannot be empty", _appCode: "framework" },
  必须包含: { "zh-CN": "必须包含", en: "It must contain ", _appCode: "framework" },
  "数字，": { "zh-CN": "数字，", en: "numbers,", _appCode: "framework" },
  "小写字母，": { "zh-CN": "小写字母，", en: "lowercase letters,", _appCode: "framework" },
  "大写字母，": { "zh-CN": "大写字母，", en: "uppercase letters,", _appCode: "framework" },
  "符号，": { "zh-CN": "符号，", en: "symbols,", _appCode: "framework" },
  "修改密码成功！": {
    "zh-CN": "修改密码成功！",
    en: "You had successfully changed the password!",
    _appCode: "framework"
  },
  修改密码: { "zh-CN": "修改密码", en: "Change Password", _appCode: "framework" },
  旧密码: { "zh-CN": "旧密码", en: "Old Password", _appCode: "framework" },
  新密码: { "zh-CN": "新密码", en: "New Password", _appCode: "framework" },
  确认新密码: { "zh-CN": "确认新密码", en: "Confirm New Password", _appCode: "framework" },
  取消: { "zh-CN": "取消", en: "Cancel", _appCode: "framework" },
  确定: { "zh-CN": "确定", en: "OK", _appCode: "framework" },
  "das-ui-business-components-change-pwd-limit-number": {
    "zh-CN": "$0~20个字符，",
    en: "$0~20 characters,",
    _appCode: "framework"
  },
  "das-ui-business-components-change-pwd-passwordFormatRule": {
    "zh-CN": "8～20个字符，至少包含数字和字母，不包含空格",
    en: "8~20 characters, at least including numbers and letters, and no spaces are allowed",
    _appCode: "framework"
  }
};
O(ae);
const Ce = B(oe), ge = () => R(null);
export {
  Ce as DasChangePwd,
  ge as DasChangePwdRef
};
