const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_usePasswordValidationRules = require("../hooks/usePasswordValidationRules.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let _ant_design_icons = require("@ant-design/icons");
//#region src/pro/Login2.0/steps/SetPassword.tsx
/**
* 设置密码页面（对应图5）
*/
function SetPassword({ flowData, onSubmit, onBack, loading = false, passwordRules = {
	minLength: 8,
	requireNumber: true
}, scenario = "create" }) {
	const [form] = antd.Form.useForm();
	const [showPassword, setShowPassword] = (0, react.useState)(false);
	const [showConfirmPassword, setShowConfirmPassword] = (0, react.useState)(false);
	const handleSubmit = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
			try {
				const values = yield form.validateFields();
				yield onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(values.password, values.confirmPassword);
			} catch (error) {
				if (error.errorFields) return;
				antd.message.error((error === null || error === void 0 ? void 0 : error.message) || _pisell_utils.locales.getText("pisell-set-password-failed"));
			}
		});
		return function handleSubmit() {
			return _ref.apply(this, arguments);
		};
	}();
	const passwordValidationRules = require_usePasswordValidationRules.default(passwordRules, {
		translate: _pisell_utils.locales.getText,
		fallbackMinLength: 8,
		messageKeys: {
			required: _pisell_utils.locales.getText("pisell-set-password-required"),
			minLength: _pisell_utils.locales.getText("pisell-set-password-min-length"),
			requireUppercase: _pisell_utils.locales.getText("pisell-set-password-require-uppercase"),
			requireLowercase: _pisell_utils.locales.getText("pisell-set-password-require-lowercase"),
			requireNumber: _pisell_utils.locales.getText("pisell-set-password-require-number"),
			requireSpecialCharacters: _pisell_utils.locales.getText("pisell-set-password-require-special"),
			summary: _pisell_utils.locales.getText("pisell-set-password-must-contain")
		}
	});
	return /* @__PURE__ */ react.default.createElement("div", { className: "register-step-container" }, /* @__PURE__ */ react.default.createElement("div", { className: "register-step-content" }, /* @__PURE__ */ react.default.createElement("h2", { className: "register-step-title" }, scenario === "create" ? _pisell_utils.locales.getText("pisell-set-password-create-title") : _pisell_utils.locales.getText("pisell-set-password-reset-title")), /* @__PURE__ */ react.default.createElement(antd.Form, {
		form,
		layout: "vertical",
		className: "password-set-form"
	}, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		name: "password",
		rules: passwordValidationRules
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Input.Password, {
		size: "large",
		placeholder: _pisell_utils.locales.getText("pisell-set-password-placeholder"),
		className: "password-input",
		autoComplete: "new-password",
		iconRender: (visible) => visible ? /* @__PURE__ */ react.default.createElement(_ant_design_icons.EyeOutlined, null) : /* @__PURE__ */ react.default.createElement(_ant_design_icons.EyeInvisibleOutlined, null)
	})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		name: "confirmPassword",
		dependencies: ["password"],
		rules: [{
			required: true,
			message: _pisell_utils.locales.getText("pisell-set-password-confirm-required")
		}, ({ getFieldValue }) => ({ validator(_, value) {
			if (!value || getFieldValue("password") === value) return Promise.resolve();
			return Promise.reject(new Error(_pisell_utils.locales.getText("pisell-set-password-not-match")));
		} })]
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Input.Password, {
		size: "large",
		placeholder: _pisell_utils.locales.getText("pisell-set-password-confirm-placeholder"),
		className: "password-input",
		autoComplete: "new-password",
		iconRender: (visible) => visible ? /* @__PURE__ */ react.default.createElement(_ant_design_icons.EyeOutlined, null) : /* @__PURE__ */ react.default.createElement(_ant_design_icons.EyeInvisibleOutlined, null)
	})), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
		type: "primary",
		size: "large",
		block: true,
		onClick: handleSubmit,
		loading,
		className: "register-submit-btn"
	}, scenario === "create" ? _pisell_utils.locales.getText("pisell-set-password-submit") : _pisell_utils.locales.getText("pisell-common-confirm")))));
}
//#endregion
exports.default = SetPassword;
