var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/pro/Login2.0/steps/SetPassword.tsx
var SetPassword_exports = {};
__export(SetPassword_exports, {
  default: () => SetPassword_default
});
module.exports = __toCommonJS(SetPassword_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_materials = require("@pisell/materials");
var import_icons = require("@ant-design/icons");
var import_utils = require("@pisell/utils");
var import_usePasswordValidationRules = __toESM(require("../hooks/usePasswordValidationRules"));
function SetPassword({
  flowData,
  onSubmit,
  onBack,
  loading = false,
  passwordRules = {
    minLength: 8,
    requireNumber: true
  },
  scenario = "create"
}) {
  const [form] = import_antd.Form.useForm();
  const [showPassword, setShowPassword] = (0, import_react.useState)(false);
  const [showConfirmPassword, setShowConfirmPassword] = (0, import_react.useState)(false);
  const handleSubmit = async () => {
    try {
      const values = await form.validateFields();
      await (onSubmit == null ? void 0 : onSubmit(values.password, values.confirmPassword));
    } catch (error) {
      if (error.errorFields) {
        return;
      }
      import_antd.message.error((error == null ? void 0 : error.message) || import_utils.locales.getText("pisell-set-password-failed"));
    }
  };
  const passwordValidationRules = (0, import_usePasswordValidationRules.default)(passwordRules, {
    translate: import_utils.locales.getText,
    fallbackMinLength: 8,
    messageKeys: {
      required: import_utils.locales.getText("pisell-set-password-required"),
      minLength: import_utils.locales.getText("pisell-set-password-min-length"),
      requireUppercase: import_utils.locales.getText("pisell-set-password-require-uppercase"),
      requireLowercase: import_utils.locales.getText("pisell-set-password-require-lowercase"),
      requireNumber: import_utils.locales.getText("pisell-set-password-require-number"),
      requireSpecialCharacters: import_utils.locales.getText("pisell-set-password-require-special"),
      summary: import_utils.locales.getText("pisell-set-password-must-contain")
    }
  });
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "register-step-container" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "register-step-content" }, /* @__PURE__ */ import_react.default.createElement("h2", { className: "register-step-title" }, scenario === "create" ? import_utils.locales.getText("pisell-set-password-create-title") : import_utils.locales.getText("pisell-set-password-reset-title")), /* @__PURE__ */ import_react.default.createElement(import_antd.Form, { form, layout: "vertical", className: "password-set-form" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { name: "password", rules: passwordValidationRules }, /* @__PURE__ */ import_react.default.createElement(
    import_materials.Input.Password,
    {
      size: "large",
      placeholder: import_utils.locales.getText("pisell-set-password-placeholder"),
      className: "password-input",
      autoComplete: "new-password",
      iconRender: (visible) => visible ? /* @__PURE__ */ import_react.default.createElement(import_icons.EyeOutlined, null) : /* @__PURE__ */ import_react.default.createElement(import_icons.EyeInvisibleOutlined, null)
    }
  )), /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      name: "confirmPassword",
      dependencies: ["password"],
      rules: [
        {
          required: true,
          message: import_utils.locales.getText("pisell-set-password-confirm-required")
        },
        ({ getFieldValue }) => ({
          validator(_, value) {
            if (!value || getFieldValue("password") === value) {
              return Promise.resolve();
            }
            return Promise.reject(new Error(import_utils.locales.getText("pisell-set-password-not-match")));
          }
        })
      ]
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_materials.Input.Password,
      {
        size: "large",
        placeholder: import_utils.locales.getText("pisell-set-password-confirm-placeholder"),
        className: "password-input",
        autoComplete: "new-password",
        iconRender: (visible) => visible ? /* @__PURE__ */ import_react.default.createElement(import_icons.EyeOutlined, null) : /* @__PURE__ */ import_react.default.createElement(import_icons.EyeInvisibleOutlined, null)
      }
    )
  ), /* @__PURE__ */ import_react.default.createElement(
    import_materials.Button,
    {
      type: "primary",
      size: "large",
      block: true,
      onClick: handleSubmit,
      loading,
      className: "register-submit-btn"
    },
    scenario === "create" ? import_utils.locales.getText("pisell-set-password-submit") : import_utils.locales.getText("pisell-common-confirm")
  ))));
}
var SetPassword_default = SetPassword;
