const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_useEngineContext = require("../../hooks/useEngineContext.js");
const require_locales = require("./locales.js");
const require_Header = require("./shared/Header.js");
const require_LoginCodeInput = require("./components/LoginCodeInput.js");
const require_usePasswordValidationRules = require("./hooks/usePasswordValidationRules.js");
const require_SetPassword = require("./steps/SetPassword.js");
const require_PhoneInput = require("./components/PhoneInput.js");
const require_phoneValidation = require("./components/phoneValidation.js");
const require_ForgotPasswordFlow = require("./components/ForgotPasswordFlow.js");
const require_LegalTerms = require("./components/LegalTerms.js");
const require_OAuthButtonGroup = require("./components/OAuthButtonGroup.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 classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let ahooks = require("ahooks");
require("./index.less");
//#region src/pro/Login2.0/Login2.tsx
/**
* 登录 2.0 组件
* 支持邮箱、手机、三方登录
* 组件宽度固定 360px
*/
const Login2 = ({ config, visible = true, onClose, className, style, onLogin, onOAuthLogin, onSendVerificationCode, onForgotPassword, onSwitchToRegister, onError }) => {
	var _context$appHelper, _config$ui, _config$emailLinkVeri, _config$emailLinkVeri2, _config$emailLinkVeri4;
	const [form] = antd.Form.useForm();
	const [loading, setLoading] = (0, react.useState)(false);
	const [countdown, setCountdown] = (0, react.useState)(0);
	const [countries, setCountries] = (0, react.useState)([]);
	const pisellOS = require_useEngineContext.usePisellOS();
	const registerAndLogin = pisellOS === null || pisellOS === void 0 ? void 0 : pisellOS.getModule("registerAndLogin");
	const context = require_useEngineContext.default();
	const storage = context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.storage;
	(0, react.useEffect)(() => {
		var _context$appHelper$ut, _context$appHelper$ut2, _context$appHelper$ut3, _context$appHelper$ut4;
		_pisell_utils.locales.init(require_locales.default, ((_context$appHelper$ut = context.appHelper.utils) === null || _context$appHelper$ut === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut.getApp) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.call(_context$appHelper$ut)) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.locales) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut3 = _context$appHelper$ut2.getLocale) === null || _context$appHelper$ut3 === void 0 ? void 0 : _context$appHelper$ut3.call(_context$appHelper$ut2)) || ((_context$appHelper$ut4 = context.appHelper.utils) === null || _context$appHelper$ut4 === void 0 || (_context$appHelper$ut4 = _context$appHelper$ut4.storage) === null || _context$appHelper$ut4 === void 0 ? void 0 : _context$appHelper$ut4.get("umi_locale")) || "en");
	}, []);
	const loginMethods = config.loginMethods || [];
	const passwordValidationRules = require_usePasswordValidationRules.default((_config$ui = config.ui) === null || _config$ui === void 0 ? void 0 : _config$ui.passwordRules, {
		translate: _pisell_utils.locales.getText,
		fallbackMinLength: 6,
		messageKeys: {
			required: _pisell_utils.locales.getText("pisell-login2-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")
		}
	});
	const [currentLoginMethod, setCurrentLoginMethod] = (0, react.useState)(null);
	const [currentVerificationMethod, setCurrentVerificationMethod] = (0, react.useState)("password");
	const hasTriggeredGuestLoginRef = (0, react.useRef)(false);
	(0, react.useEffect)(() => {
		if (loginMethods.length > 0 && !currentLoginMethod) {
			const initialMethod = loginMethods[0];
			setCurrentLoginMethod(initialMethod);
			if ((initialMethod === null || initialMethod === void 0 ? void 0 : initialMethod.type) === "email" || (initialMethod === null || initialMethod === void 0 ? void 0 : initialMethod.type) === "phone") {
				var _initialMethod$verifi;
				setCurrentVerificationMethod(((_initialMethod$verifi = initialMethod.verificationMethods) === null || _initialMethod$verifi === void 0 ? void 0 : _initialMethod$verifi[0]) || "password");
			}
		}
		if (hasTriggeredGuestLoginRef.current) return;
		if (!(loginMethods.length === 1 && loginMethods[0].type === "guest")) return;
		hasTriggeredGuestLoginRef.current = true;
		handleGuestLogin();
	}, [loginMethods, currentLoginMethod]);
	(0, react.useEffect)(() => {
		if (((currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.type) === "email" || (currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.type) === "phone") && currentVerificationMethod === "password") {
			const storedRememberMe = storage.get("login_remember_me") === "true";
			setRememberMe(storedRememberMe);
			let account = storage.get("login_account");
			try {
				account = JSON.parse(account || "{}");
			} catch (e) {
				console.error(e);
			}
			if (account && storedRememberMe) {
				const accountString = typeof account === "string" ? account : account.phone || account.email || "";
				const isEmail = accountString.includes("@");
				const isPhone = /^\d+$/.test(accountString.replace(/\+/g, "").replace(/\s/g, ""));
				if (currentLoginMethod.type === "email" && isEmail || currentLoginMethod.type === "phone" && isPhone) {
					setEnteredAccount(account);
					setHasStoredCredentials(true);
					if (isEmail && !form.getFieldValue("email")) form.setFieldsValue({ email: account });
					if (isPhone && !form.getFieldValue("phone")) form.setFieldsValue({ phone: account });
					if (currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.stepByStep) setLoginStep("password");
				} else {
					setHasStoredCredentials(false);
					setEnteredAccount("");
				}
			} else setHasStoredCredentials(false);
		}
	}, [currentLoginMethod, currentVerificationMethod]);
	(0, react.useEffect)(() => {
		if (!visible) form.setFieldsValue({ password: "" });
	}, [visible, form]);
	const [loginStep, setLoginStep] = (0, react.useState)("account");
	const [enteredAccount, setEnteredAccount] = (0, react.useState)("");
	const [codeError, setCodeError] = (0, react.useState)("");
	const [rememberMe, setRememberMe] = (0, react.useState)(false);
	const [hasStoredCredentials, setHasStoredCredentials] = (0, react.useState)(false);
	const [lastLoginMethod, setLastLoginMethod] = (0, react.useState)(null);
	const [showForgotPassword, setShowForgotPassword] = (0, react.useState)(false);
	const [emailLinkVerifyStatus, setEmailLinkVerifyStatus] = (0, react.useState)(null);
	const [emailLinkError, setEmailLinkError] = (0, react.useState)("");
	const [resetPasswordUserEmail, setResetPasswordUserEmail] = (0, react.useState)("");
	const isEmailLinkVerification = ((_config$emailLinkVeri = config.emailLinkVerification) === null || _config$emailLinkVeri === void 0 ? void 0 : _config$emailLinkVeri.enabled) && ((_config$emailLinkVeri2 = config.emailLinkVerification) === null || _config$emailLinkVeri2 === void 0 ? void 0 : _config$emailLinkVeri2.code);
	(0, react.useEffect)(() => {
		var _config$emailLinkVeri3;
		if (isEmailLinkVerification && ((_config$emailLinkVeri3 = config.emailLinkVerification) === null || _config$emailLinkVeri3 === void 0 ? void 0 : _config$emailLinkVeri3.code)) {
			setEmailLinkVerifyStatus("verifying");
			(function() {
				var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
					try {
						if (registerAndLogin === null || registerAndLogin === void 0 ? void 0 : registerAndLogin.checkResetPasswordCode) {
							const result = yield registerAndLogin.checkResetPasswordCode({ code: config.emailLinkVerification.code });
							if (result.status) {
								var _result$data;
								setEmailLinkVerifyStatus("success");
								if ((_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.email) setResetPasswordUserEmail(result.data.email);
							} else {
								setEmailLinkVerifyStatus("error");
								setEmailLinkError(result.message || "验证码无效或已过期");
							}
						} else {
							setEmailLinkVerifyStatus("error");
							setEmailLinkError("系统错误，请稍后重试");
						}
					} catch (error) {
						setEmailLinkVerifyStatus("error");
						setEmailLinkError("网络错误，请稍后重试");
					}
				});
				return function checkCode() {
					return _ref.apply(this, arguments);
				};
			})()();
		}
	}, [
		isEmailLinkVerification,
		(_config$emailLinkVeri4 = config.emailLinkVerification) === null || _config$emailLinkVeri4 === void 0 ? void 0 : _config$emailLinkVeri4.code,
		registerAndLogin
	]);
	(0, react.useEffect)(() => {
		if (countdown > 0) {
			const timer = setTimeout(() => {
				setCountdown(countdown - 1);
			}, 1e3);
			return () => clearTimeout(timer);
		}
	}, [countdown]);
	(0, react.useEffect)(() => {
		(function() {
			var _ref2 = require_asyncToGenerator._asyncToGenerator(function* () {
				try {
					if (registerAndLogin === null || registerAndLogin === void 0 ? void 0 : registerAndLogin.getCountries) setCountries((yield registerAndLogin.getCountries()) || []);
				} catch (error) {
					console.error("Failed to fetch countries:", error);
				}
			});
			return function fetchCountries() {
				return _ref2.apply(this, arguments);
			};
		})()();
	}, [registerAndLogin]);
	(0, react.useEffect)(() => {
		try {
			const storedLoginMethod = storage.get("pisell_last_login_method");
			if (storedLoginMethod) setLastLoginMethod(JSON.parse(storedLoginMethod));
			const rememberMe = storage.get("login_remember_me") === "true";
			const account = storage.get("login_account");
			const password = storage.get("login_password");
			if (rememberMe && account && password) {
				let accountData;
				try {
					accountData = JSON.parse(account || "{}");
				} catch (e) {
					accountData = account;
				}
				const isEmail = typeof accountData === "string" && accountData.includes("@");
				const loginMethod = loginMethods.find((m) => m.type === (isEmail ? "email" : "phone"));
				if (loginMethod) {
					setCurrentLoginMethod(loginMethod);
					setCurrentVerificationMethod("password");
					setEnteredAccount(accountData);
					const accountFieldName = isEmail ? "email" : "phone";
					form.setFieldsValue({
						[accountFieldName]: accountData,
						password,
						remember_me: true
					});
					setLoginStep("password");
					setRememberMe(true);
				}
			}
		} catch (error) {
			console.error("Failed to parse last login method:", error);
		}
	}, [loginMethods]);
	const isLastLoginMethod = (0, react.useCallback)((methodType) => {
		if (!lastLoginMethod) return false;
		return lastLoginMethod.type === methodType;
	}, [lastLoginMethod]);
	const switchVerificationMethod = (0, react.useCallback)((method) => {
		form.resetFields();
		setLoginStep("account");
		setEnteredAccount("");
		setCurrentVerificationMethod(method);
	}, [form]);
	const switchLoginMethod = (0, react.useCallback)((method) => {
		form.resetFields();
		setLoginStep("account");
		setEnteredAccount("");
		setHasStoredCredentials(false);
		setCurrentLoginMethod(method);
		if (method.type === "email" || method.type === "phone") setCurrentVerificationMethod(method.verificationMethods[0]);
	}, [form]);
	const { run: handleContinueWithAccount } = (0, ahooks.useDebounceFn)(function() {
		var _ref3 = require_asyncToGenerator._asyncToGenerator(function* () {
			try {
				setLoading(true);
				const accountFieldName = (currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.type) === "email" ? "email" : "phone";
				const account = (yield form.validateFields([accountFieldName]))[accountFieldName];
				if ((currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.type) === "email" && registerAndLogin) {
					var _context$appHelper2, _utils$getStore, _utils$getStore$getSt;
					const utils = (context === null || context === void 0 || (_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 ? void 0 : _context$appHelper2.utils) || {};
					const shopId = ((_utils$getStore = utils.getStore) === null || _utils$getStore === void 0 || (_utils$getStore = _utils$getStore.call(utils)) === null || _utils$getStore === void 0 || (_utils$getStore$getSt = _utils$getStore.getState) === null || _utils$getStore$getSt === void 0 || (_utils$getStore$getSt = _utils$getStore$getSt.call(_utils$getStore)) === null || _utils$getStore$getSt === void 0 || (_utils$getStore$getSt = _utils$getStore$getSt.global) === null || _utils$getStore$getSt === void 0 || (_utils$getStore$getSt = _utils$getStore$getSt.shop) === null || _utils$getStore$getSt === void 0 ? void 0 : _utils$getStore$getSt.id) || 9;
					const result = yield registerAndLogin.checkEmailExists({
						email: account,
						shop_id: shopId
					});
					if (result.status && result.data) if (result.data.exists) {
						setEnteredAccount(account);
						setLoginStep("password");
						form.setFieldsValue({ [accountFieldName]: account });
					} else {
						antd.message.error(_pisell_utils.locales.getText("pisell-login2-email-not-registered"));
						return;
					}
					else {
						antd.message.error(result.message || _pisell_utils.locales.getText("pisell-login2-check-email-failed"));
						return;
					}
				} else {
					setEnteredAccount(account);
					setLoginStep("password");
					form.setFieldsValue({ [accountFieldName]: account });
				}
			} catch (error) {
				if (error.errorFields) return;
				console.error("Continue with account error:", error);
				antd.message.error((error === null || error === void 0 ? void 0 : error.message) || _pisell_utils.locales.getText("pisell-login2-continue-failed"));
			} finally {
				setLoading(false);
			}
		});
		return function handleContinueWithAccountInternal() {
			return _ref3.apply(this, arguments);
		};
	}(), {
		wait: 200,
		leading: true,
		trailing: false
	});
	const handleBackToAccountInternal = () => {
		setLoginStep("account");
		form.resetFields(["password"]);
	};
	const { run: handleBackToAccount } = (0, ahooks.useDebounceFn)(handleBackToAccountInternal, {
		wait: 200,
		leading: true,
		trailing: false
	});
	const handleSendCode = function() {
		var _ref4 = require_asyncToGenerator._asyncToGenerator(function* () {
			try {
				const accountFieldName = (currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.type) === "email" ? "email" : "phone";
				yield form.validateFields([accountFieldName]);
				const account = form.getFieldValue(accountFieldName);
				if (!account) {
					antd.message.error(_pisell_utils.locales.getText("pisell-login2-account-required"));
					return;
				}
				setLoading(true);
				const type = (currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.type) === "email" ? "email" : "phone";
				if (registerAndLogin) {
					let res;
					if (type === "email") res = yield registerAndLogin.sendEmailLoginCode({
						type: "email",
						target: account,
						purpose: "login"
					});
					else {
						let phoneData;
						if (typeof account === "string") {
							var _countries$find;
							phoneData = {
								phone: account,
								country_calling_code: ((_countries$find = countries.find((country) => country.value === account)) === null || _countries$find === void 0 ? void 0 : _countries$find.calling_code) || ""
							};
						} else phoneData = account;
						res = yield registerAndLogin.sendSmsLoginCode(phoneData);
					}
					if ((res === null || res === void 0 ? void 0 : res.code) !== 200) throw new Error((res === null || res === void 0 ? void 0 : res.message) || _pisell_utils.locales.getText("pisell-login2-code-send-failed"));
				}
				yield onSendVerificationCode === null || onSendVerificationCode === void 0 ? void 0 : onSendVerificationCode(account, type, config.channel);
				setEnteredAccount(account);
				setLoginStep("code");
				setCountdown(60);
				antd.message.success(_pisell_utils.locales.getText("pisell-login2-code-sent"));
			} catch (error) {
				if (error === null || error === void 0 ? void 0 : error.errorFields) return;
				antd.message.error((error === null || error === void 0 ? void 0 : error.message) || _pisell_utils.locales.getText("pisell-login2-code-send-failed"));
			} finally {
				setLoading(false);
			}
		});
		return function handleSendCode() {
			return _ref4.apply(this, arguments);
		};
	}();
	const handleCodeSubmit = function() {
		var _ref5 = require_asyncToGenerator._asyncToGenerator(function* (code) {
			try {
				setLoading(true);
				setCodeError("");
				const method = (currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.type) || "email";
				let result;
				if (registerAndLogin) {
					if (method === "email") result = yield registerAndLogin.emailCodeLogin({
						email: enteredAccount,
						code
					});
					else if (method === "phone") {
						let phoneData;
						if (typeof enteredAccount === "string") {
							var _countries$find2;
							phoneData = {
								phone: enteredAccount,
								country_calling_code: ((_countries$find2 = countries.find((country) => country.value === enteredAccount)) === null || _countries$find2 === void 0 ? void 0 : _countries$find2.calling_code) || ""
							};
						} else phoneData = enteredAccount;
						result = yield registerAndLogin.phoneCodeLogin({
							phone: phoneData.phone,
							country_calling_code: phoneData.country_calling_code,
							code
						});
					}
					if ((result === null || result === void 0 ? void 0 : result.code) !== 200) {
						const errorMessage = (result === null || result === void 0 ? void 0 : result.message) || _pisell_utils.locales.getText("pisell-login2-login-failed");
						const error = new Error(errorMessage);
						onError === null || onError === void 0 || onError(error, method);
						setCodeError(errorMessage);
						return;
					}
				}
				const loginData = {
					account: enteredAccount,
					password: void 0,
					verification_code: code,
					remember_me: false
				};
				yield onLogin === null || onLogin === void 0 ? void 0 : onLogin(result.data, method, loginData, config.channel);
				antd.message.success(_pisell_utils.locales.getText("pisell-login2-login-success"));
			} catch (error) {
				setCodeError((error === null || error === void 0 ? void 0 : error.message) || _pisell_utils.locales.getText("pisell-login2-login-failed"));
			} finally {
				setLoading(false);
			}
		});
		return function handleCodeSubmit(_x) {
			return _ref5.apply(this, arguments);
		};
	}();
	const handleBackFromCode = () => {
		setLoginStep("account");
		form.resetFields();
		setCodeError("");
	};
	const handleForgotPasswordClickInternal = () => {
		const accountFieldName = (currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.type) === "email" ? "email" : "phone";
		setEnteredAccount(form.getFieldValue(accountFieldName) || "");
		setShowForgotPassword(true);
	};
	const { run: handleForgotPasswordClick } = (0, ahooks.useDebounceFn)(handleForgotPasswordClickInternal, {
		wait: 200,
		leading: true,
		trailing: false
	});
	const handleCloseForgotPassword = () => {
		setShowForgotPassword(false);
		setCountdown(0);
	};
	const handleForgotPasswordSendLink = function() {
		var _ref6 = require_asyncToGenerator._asyncToGenerator(function* (account) {
			try {
				setLoading(true);
				if (registerAndLogin) {
					const res = yield registerAndLogin.sendResetPasswordLink({ email: account });
					if (!res.status) throw new Error(res.message || "发送重置密码链接失败");
				}
				antd.message.success(_pisell_utils.locales.getText("pisell-forgot-password-link-sent"));
			} catch (error) {
				antd.message.error((error === null || error === void 0 ? void 0 : error.message) || "发送重置密码链接失败");
				throw error;
			} finally {
				setLoading(false);
			}
		});
		return function handleForgotPasswordSendLink(_x2) {
			return _ref6.apply(this, arguments);
		};
	}();
	const handleForgotPasswordSendCode = function() {
		var _ref7 = require_asyncToGenerator._asyncToGenerator(function* (account) {
			try {
				setLoading(true);
				const type = (currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.type) === "email" ? "email" : "phone";
				if (registerAndLogin) if (type === "email") {
					const res = yield registerAndLogin.sendPasswordResetEmail({ email: account });
					if (!res.status) throw new Error(res.message || _pisell_utils.locales.getText("pisell-login2-code-send-failed"));
				} else {
					const phoneAccount = account;
					const res = yield registerAndLogin.sendPasswordResetSms({
						phone: phoneAccount.phone,
						country_calling_code: phoneAccount.country_calling_code
					});
					if (!res.status) throw new Error(res.message || _pisell_utils.locales.getText("pisell-login2-code-send-failed"));
				}
				setCountdown(60);
				antd.message.success(_pisell_utils.locales.getText("pisell-login2-code-sent"));
			} catch (error) {
				antd.message.error((error === null || error === void 0 ? void 0 : error.message) || _pisell_utils.locales.getText("pisell-login2-code-send-failed"));
				throw error;
			} finally {
				setLoading(false);
			}
		});
		return function handleForgotPasswordSendCode(_x3) {
			return _ref7.apply(this, arguments);
		};
	}();
	const handleForgotPasswordVerifyCode = function() {
		var _ref8 = require_asyncToGenerator._asyncToGenerator(function* (account, code) {
			try {
				setLoading(true);
				if (registerAndLogin) {
					var _context$appHelper3, _utils$getStore2, _utils$getStore2$getS;
					const utils = (context === null || context === void 0 || (_context$appHelper3 = context.appHelper) === null || _context$appHelper3 === void 0 ? void 0 : _context$appHelper3.utils) || {};
					const shopId = ((_utils$getStore2 = utils.getStore) === null || _utils$getStore2 === void 0 || (_utils$getStore2 = _utils$getStore2.call(utils)) === null || _utils$getStore2 === void 0 || (_utils$getStore2$getS = _utils$getStore2.getState) === null || _utils$getStore2$getS === void 0 || (_utils$getStore2$getS = _utils$getStore2$getS.call(_utils$getStore2)) === null || _utils$getStore2$getS === void 0 || (_utils$getStore2$getS = _utils$getStore2$getS.global) === null || _utils$getStore2$getS === void 0 || (_utils$getStore2$getS = _utils$getStore2$getS.shop) === null || _utils$getStore2$getS === void 0 ? void 0 : _utils$getStore2$getS.id) || 9;
					const isPhoneAccount = typeof account === "object" && "phone" in account;
					let res;
					if (!isPhoneAccount) res = yield registerAndLogin.checkEmailCode({
						email: account,
						shop_id: shopId,
						code,
						action: "customer_reset_password_code"
					});
					else {
						const phoneData = account;
						res = yield registerAndLogin.checkMobileCode({
							phone: phoneData.phone,
							country_calling_code: phoneData.country_calling_code,
							code,
							action: "forget"
						});
					}
					if (!res.status) throw new Error(res.message || "验证码验证失败");
					if (!res.data.valid) throw new Error(_pisell_utils.locales.getText("pisell-login2-code-verify-failed"));
				}
			} catch (error) {
				antd.message.error((error === null || error === void 0 ? void 0 : error.message) || "验证码验证失败");
				throw error;
			} finally {
				setLoading(false);
			}
		});
		return function handleForgotPasswordVerifyCode(_x4, _x5) {
			return _ref8.apply(this, arguments);
		};
	}();
	const handleForgotPasswordReset = function() {
		var _ref9 = require_asyncToGenerator._asyncToGenerator(function* (account, password, code) {
			try {
				setLoading(true);
				if (registerAndLogin) {
					const isPhoneAccount = typeof account === "object" && "phone" in account;
					let resetPasswordParams;
					if (isPhoneAccount) resetPasswordParams = {
						type: "phone",
						target: {
							phone: account.phone,
							country_calling_code: account.country_calling_code
						},
						password,
						code
					};
					else resetPasswordParams = {
						type: "email",
						target: { email: account },
						password,
						code
					};
					const res = yield registerAndLogin.resetPassword(resetPasswordParams);
					if ((res === null || res === void 0 ? void 0 : res.code) !== 200) throw new Error((res === null || res === void 0 ? void 0 : res.message) || _pisell_utils.locales.getText("pisell-forgot-password-failed"));
				}
				handleCloseForgotPassword();
				if (typeof account === "object" && "phone" in account) {
					const phoneMethod = config.loginMethods.find((method) => method.type === "phone");
					if (phoneMethod) {
						setCurrentLoginMethod(phoneMethod);
						setCurrentVerificationMethod(phoneMethod.verificationMethods[0]);
					}
					form.setFieldsValue({ phone: account });
					setEnteredAccount(account);
				} else {
					const emailMethod = config.loginMethods.find((method) => method.type === "email");
					if (emailMethod) {
						setCurrentLoginMethod(emailMethod);
						setCurrentVerificationMethod(emailMethod.verificationMethods[0]);
					}
					form.setFieldsValue({ email: account });
					setEnteredAccount(account);
				}
				setLoginStep("account");
			} catch (error) {
				antd.message.error((error === null || error === void 0 ? void 0 : error.message) || _pisell_utils.locales.getText("pisell-forgot-password-failed"));
			} finally {
				setLoading(false);
			}
		});
		return function handleForgotPasswordReset(_x6, _x7, _x8) {
			return _ref9.apply(this, arguments);
		};
	}();
	const handleEmailLinkResetPassword = function() {
		var _ref10 = require_asyncToGenerator._asyncToGenerator(function* (account, password, code) {
			try {
				setLoading(true);
				if (registerAndLogin) {
					const res = yield registerAndLogin.resetPasswordByCode({
						code: config.emailLinkVerification.code,
						password
					});
					if ((res === null || res === void 0 ? void 0 : res.code) !== 200) throw new Error((res === null || res === void 0 ? void 0 : res.message) || _pisell_utils.locales.getText("pisell-forgot-password-failed"));
				}
				handleCloseForgotPassword();
				setEmailLinkVerifyStatus(null);
				antd.message.success(_pisell_utils.locales.getText("pisell-forgot-password-success"));
			} catch (error) {
				antd.message.error((error === null || error === void 0 ? void 0 : error.message) || _pisell_utils.locales.getText("pisell-forgot-password-failed"));
				throw error;
			} finally {
				setLoading(false);
			}
		});
		return function handleEmailLinkResetPassword(_x9, _x10, _x11) {
			return _ref10.apply(this, arguments);
		};
	}();
	const { run: handleGuestLogin } = (0, ahooks.useDebounceFn)(function() {
		var _ref11 = require_asyncToGenerator._asyncToGenerator(function* () {
			try {
				setLoading(true);
				if (registerAndLogin) {
					const result = yield registerAndLogin.guestLogin();
					if (result.code === 200) {
						antd.message.success(_pisell_utils.locales.getText("pisell-login2-login-success"));
						const loginMethodInfo = {
							type: "guest",
							verificationMethod: null,
							timestamp: Date.now()
						};
						storage.set("pisell_last_login_method", JSON.stringify(loginMethodInfo));
						onLogin === null || onLogin === void 0 || onLogin(result.data, "guest", {
							account: "guest",
							password: void 0
						}, config.channel);
					} else antd.message.error(result.message || _pisell_utils.locales.getText("pisell-login2-login-failed"));
				}
			} catch (error) {
				console.error("Guest login error:", error);
				antd.message.error(_pisell_utils.locales.getText("pisell-login2-login-failed"));
			} finally {
				setLoading(false);
			}
		});
		return function handleGuestLoginInternal() {
			return _ref11.apply(this, arguments);
		};
	}(), {
		wait: 200,
		leading: true,
		trailing: false
	});
	const { run: handleLogin } = (0, ahooks.useDebounceFn)(function() {
		var _ref12 = require_asyncToGenerator._asyncToGenerator(function* () {
			try {
				setLoading(true);
				const values = yield form.validateFields();
				const account = values[(currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.type) === "email" ? "email" : "phone"] || values.account;
				const loginData = {
					account,
					password: currentVerificationMethod === "password" ? values.password : void 0,
					verification_code: currentVerificationMethod === "verification_code" ? values.verification_code : void 0,
					remember_me: values.remember_me
				};
				const method = (currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.type) || "email";
				let result;
				if (registerAndLogin) {
					if (method === "email") if (currentVerificationMethod === "password") result = yield registerAndLogin.emailPasswordLogin({
						email: account,
						password: values.password
					});
					else result = yield registerAndLogin.emailCodeLogin({
						email: account,
						code: values.verification_code
					});
					else if (method === "phone") {
						let phoneData;
						if (typeof account === "string") {
							var _countries$find3;
							phoneData = {
								phone: account,
								country_calling_code: ((_countries$find3 = countries.find((country) => country.value === account)) === null || _countries$find3 === void 0 ? void 0 : _countries$find3.calling_code) || ""
							};
						} else phoneData = account;
						if (currentVerificationMethod === "password") result = yield registerAndLogin.phonePasswordLogin({
							phone: phoneData.phone,
							country_calling_code: phoneData.country_calling_code,
							password: values.password
						});
						else result = yield registerAndLogin.phoneCodeLogin({
							phone: phoneData.phone,
							country_calling_code: phoneData.country_calling_code,
							code: values.verification_code
						});
					}
					if ((result === null || result === void 0 ? void 0 : result.code) !== 200) throw new Error((result === null || result === void 0 ? void 0 : result.message) || _pisell_utils.locales.getText("pisell-login2-login-failed"));
				}
				yield onLogin === null || onLogin === void 0 ? void 0 : onLogin(result.data, method, loginData, config.channel);
				const loginMethodInfo = {
					type: method,
					verificationMethod: currentVerificationMethod,
					timestamp: Date.now()
				};
				storage.set("pisell_last_login_method", JSON.stringify(loginMethodInfo));
				if (values.remember_me && account) {
					storage.set("login_account", JSON.stringify(account));
					storage.set("login_remember_me", "true");
					if (currentVerificationMethod === "password") storage.set("login_password", values.password);
					setEnteredAccount(account);
				} else {
					storage.remove("login_account");
					storage.remove("login_remember_me");
					storage.remove("login_password");
				}
				antd.message.success(_pisell_utils.locales.getText("pisell-login2-login-success"));
			} catch (error) {
				if (error.errorFields) return;
				antd.message.error((error === null || error === void 0 ? void 0 : error.message) || _pisell_utils.locales.getText("pisell-login2-login-failed"));
			} finally {
				setLoading(false);
			}
		});
		return function handleLoginInternal() {
			return _ref12.apply(this, arguments);
		};
	}(), {
		wait: 1e3,
		leading: true,
		trailing: false
	});
	const { run: handleOAuthClick } = (0, ahooks.useDebounceFn)(function() {
		var _ref13 = require_asyncToGenerator._asyncToGenerator(function* (provider) {
			try {
				setLoading(true);
				if (provider === "facebook") {
					var _config$loginMethods;
					const fbConfig = config === null || config === void 0 || (_config$loginMethods = config.loginMethods) === null || _config$loginMethods === void 0 ? void 0 : _config$loginMethods.find((n) => n.type === "facebook");
					const token = fbConfig === null || fbConfig === void 0 ? void 0 : fbConfig.appId;
					if (token) {
						const res = yield registerAndLogin.loginWithFacebook(token);
						if (res.status) onLogin === null || onLogin === void 0 || onLogin(res.data, "facebook", {
							account: "",
							password: ""
						}, config.channel);
					} else throw new Error("Facebook app_id not configured");
				} else if (provider === "apple") {
					var _config$loginMethods2;
					const appleConfig = config === null || config === void 0 || (_config$loginMethods2 = config.loginMethods) === null || _config$loginMethods2 === void 0 ? void 0 : _config$loginMethods2.find((n) => n.type === "apple");
					const token = appleConfig === null || appleConfig === void 0 ? void 0 : appleConfig.clientId;
					if (token) {
						const res = yield registerAndLogin.loginWithApple(token);
						onLogin === null || onLogin === void 0 || onLogin(res.data, "apple", {
							account: "",
							password: ""
						}, config.channel);
					} else throw new Error("Apple client_id not configured");
				} else yield onOAuthLogin === null || onOAuthLogin === void 0 ? void 0 : onOAuthLogin(provider, config.channel);
			} catch (error) {
				if (error.message === "facebook_login_cancel") return antd.message.error(_pisell_utils.locales.getText("pisell-register2-facebook-login-canceled"));
				antd.message.error((error === null || error === void 0 ? void 0 : error.message) || _pisell_utils.locales.getText("pisell-login2-login-failed"));
			} finally {
				setLoading(false);
			}
		});
		return function handleOAuthClickInternal(_x12) {
			return _ref13.apply(this, arguments);
		};
	}(), {
		wait: 200,
		leading: true,
		trailing: false
	});
	const oauthProviders = (0, react.useMemo)(() => {
		return loginMethods.filter((method) => [
			"google",
			"facebook",
			"apple",
			"guest"
		].includes(method.type)).map((method) => {
			const isLast = isLastLoginMethod(method.type);
			const commonConfig = {
				className: (0, classnames.default)("login2-oauth-button", method.type, { "has-last-login-badge": isLast }),
				badge: isLast ? _pisell_utils.locales.getText("pisell-login2-last-login-badge") : void 0,
				badgeClassName: "last-login-badge"
			};
			switch (method.type) {
				case "google": return require_objectSpread2._objectSpread2({
					key: "google",
					label: /* @__PURE__ */ react.default.createElement("span", null, _pisell_utils.locales.getText("pisell-login2-continue-with"), " Google"),
					icon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-google" }),
					onClick: () => handleOAuthClick("google")
				}, commonConfig);
				case "facebook": return require_objectSpread2._objectSpread2({
					key: "facebook",
					label: /* @__PURE__ */ react.default.createElement("span", null, _pisell_utils.locales.getText("pisell-login2-continue-with"), " Facebook"),
					icon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-facebook" }),
					onClick: () => handleOAuthClick("facebook")
				}, commonConfig);
				case "apple": return require_objectSpread2._objectSpread2({
					key: "apple",
					label: /* @__PURE__ */ react.default.createElement("span", null, _pisell_utils.locales.getText("pisell-login2-continue-with"), " Apple"),
					icon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-apple" }),
					onClick: () => handleOAuthClick("apple")
				}, commonConfig);
				case "guest": return require_objectSpread2._objectSpread2({
					key: "guest",
					label: _pisell_utils.locales.getText("pisell-login2-login-as-guest"),
					icon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-user-01" }),
					onClick: handleGuestLogin
				}, commonConfig);
				default: return null;
			}
		}).filter(Boolean);
	}, [
		handleGuestLogin,
		handleOAuthClick,
		isLastLoginMethod,
		loginMethods
	]);
	const renderMainLoginForm = () => {
		var _config$ui2, _config$ui3, _config$ui4, _config$ui5, _config$ui8, _config$ui9;
		if (!currentLoginMethod) return null;
		const { type } = currentLoginMethod;
		if (type === "google" || type === "facebook" || type === "apple" || type === "guest") return null;
		if (!loginMethods.some((method) => method.type === "email" || method.type === "phone")) return null;
		const isEmail = type === "email";
		const isPhone = type === "phone";
		const accountFieldName = isEmail ? "email" : "phone";
		const getAccountValue = (values) => {
			if (values) return values[accountFieldName] || values.account;
			return form.getFieldValue(accountFieldName) || form.getFieldValue("account");
		};
		const accountLabel = isEmail ? ((_config$ui2 = config.ui) === null || _config$ui2 === void 0 || (_config$ui2 = _config$ui2.formLabels) === null || _config$ui2 === void 0 || (_config$ui2 = _config$ui2.email) === null || _config$ui2 === void 0 ? void 0 : _config$ui2.show) !== false ? ((_config$ui3 = config.ui) === null || _config$ui3 === void 0 || (_config$ui3 = _config$ui3.formLabels) === null || _config$ui3 === void 0 || (_config$ui3 = _config$ui3.email) === null || _config$ui3 === void 0 ? void 0 : _config$ui3.text) || _pisell_utils.locales.getText("pisell-login2-email-label") : void 0 : ((_config$ui4 = config.ui) === null || _config$ui4 === void 0 || (_config$ui4 = _config$ui4.formLabels) === null || _config$ui4 === void 0 || (_config$ui4 = _config$ui4.phone) === null || _config$ui4 === void 0 ? void 0 : _config$ui4.show) !== false ? ((_config$ui5 = config.ui) === null || _config$ui5 === void 0 || (_config$ui5 = _config$ui5.formLabels) === null || _config$ui5 === void 0 || (_config$ui5 = _config$ui5.phone) === null || _config$ui5 === void 0 ? void 0 : _config$ui5.text) || _pisell_utils.locales.getText("pisell-login2-phone-label") : void 0;
		const accountPlaceholder = isEmail ? _pisell_utils.locales.getText("pisell-login2-email-placeholder") : _pisell_utils.locales.getText("pisell-login2-phone-placeholder");
		const accountRules = isEmail ? [{
			required: true,
			message: _pisell_utils.locales.getText("pisell-login2-email-required")
		}, {
			type: "email",
			message: _pisell_utils.locales.getText("pisell-login2-email-invalid")
		}] : require_phoneValidation.createPhoneValidationRules(_pisell_utils.locales.getText, true);
		if ((currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.stepByStep) && currentVerificationMethod === "password") {
			var _getAccountValue, _getAccountValue2, _config$ui6, _config$ui7;
			const isPasswordStep = loginStep === "password";
			const showPasswordField = isPasswordStep;
			const handleFormSubmit = (e) => {
				e === null || e === void 0 || e.preventDefault();
				if (isPasswordStep) handleLogin();
				else handleContinueWithAccount();
			};
			return /* @__PURE__ */ react.default.createElement(antd.Form, {
				form,
				layout: "vertical",
				className: "login2-form",
				size: "large"
			}, (isEmail || isPhone) && !showPasswordField && /* @__PURE__ */ react.default.createElement("div", { style: {
				position: "absolute",
				left: "-9999px",
				opacity: 0,
				pointerEvents: "none"
			} }, /* @__PURE__ */ react.default.createElement("input", {
				type: "text",
				name: "username",
				autoComplete: "username",
				tabIndex: -1,
				readOnly: true,
				"aria-hidden": "true"
			})), showPasswordField && /* @__PURE__ */ react.default.createElement("div", { className: "login2-account-show-text-edit" }, /* @__PURE__ */ react.default.createElement("span", { className: "login2-account-show-text-edit-text" }, isPhone && `+${(_getAccountValue = getAccountValue()) === null || _getAccountValue === void 0 ? void 0 : _getAccountValue.country_calling_code}${(_getAccountValue2 = getAccountValue()) === null || _getAccountValue2 === void 0 ? void 0 : _getAccountValue2.phone}` || "", isEmail && getAccountValue() || ""), /* @__PURE__ */ react.default.createElement("span", {
				className: "login2-account-show-text-edit-icon",
				onClick: handleBackToAccount
			}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-edit-05" }))), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
				style: { display: showPasswordField ? "none" : "block" },
				label: accountLabel,
				name: isEmail ? "email" : "phone",
				rules: accountRules,
				validateTrigger: ["onBlur", "onSubmit"],
				className: isPhone ? "phone-input-form-item" : ""
			}, isPhone ? /* @__PURE__ */ react.default.createElement(require_PhoneInput.default, {
				size: "large",
				placeholder: accountPlaceholder,
				className: "login2-phone-input",
				countries,
				valueFormat: "object",
				value: isPasswordStep ? enteredAccount : getAccountValue() || void 0,
				onChange: (value) => {
					if (isPasswordStep) setEnteredAccount(value);
					form.setFieldsValue({ [accountFieldName]: value });
				}
			}) : /* @__PURE__ */ react.default.createElement(_pisell_materials.Input, {
				size: "large",
				placeholder: accountPlaceholder,
				className: "login2-input",
				type: "email",
				autoComplete: "email",
				value: getAccountValue() || enteredAccount || "",
				onChange: (e) => {
					const newValue = e.target.value;
					if (isPasswordStep) setEnteredAccount(newValue);
					form.setFieldsValue({ [accountFieldName]: newValue });
				},
				onKeyDown: (e) => {
					if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
						e.preventDefault();
						handleFormSubmit(e);
					}
				}
			})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
				style: { display: showPasswordField ? "block" : "none" },
				label: ((_config$ui6 = config.ui) === null || _config$ui6 === void 0 || (_config$ui6 = _config$ui6.formLabels) === null || _config$ui6 === void 0 || (_config$ui6 = _config$ui6.password) === null || _config$ui6 === void 0 ? void 0 : _config$ui6.show) !== false ? ((_config$ui7 = config.ui) === null || _config$ui7 === void 0 || (_config$ui7 = _config$ui7.formLabels) === null || _config$ui7 === void 0 || (_config$ui7 = _config$ui7.password) === null || _config$ui7 === void 0 ? void 0 : _config$ui7.text) || _pisell_utils.locales.getText("pisell-login2-password-label") : void 0,
				name: "password",
				validateTrigger: ["onBlur", "onSubmit"],
				rules: passwordValidationRules
			}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Input.Password, {
				size: "large",
				placeholder: _pisell_utils.locales.getText("pisell-login2-password-placeholder"),
				className: "login2-input",
				name: "password",
				autoComplete: "current-password",
				type: "password",
				autoFocus: hasStoredCredentials,
				onKeyDown: (e) => {
					if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
						e.preventDefault();
						handleFormSubmit(e);
					}
				}
			})), showPasswordField && /* @__PURE__ */ react.default.createElement("div", { className: "login2-form-footer" }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
				name: "remember_me",
				valuePropName: "checked",
				noStyle: true
			}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Checkbox, { defaultChecked: rememberMe }, _pisell_utils.locales.getText("pisell-login2-remember-me"))), /* @__PURE__ */ react.default.createElement("a", {
				className: "login2-link",
				onClick: handleForgotPasswordClick
			}, _pisell_utils.locales.getText("pisell-login2-forgot-password"))), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
				type: "primary",
				size: "large",
				block: true,
				htmlType: "button",
				loading,
				onClick: handleFormSubmit,
				className: "login2-submit-button"
			}, isPasswordStep ? _pisell_utils.locales.getText("pisell-login2-login-button") : isEmail ? _pisell_utils.locales.getText("pisell-login2-continue-with-email") : _pisell_utils.locales.getText("pisell-login2-continue-with-phone")), showPasswordField && /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
				size: "large",
				block: true,
				onClick: handleBackToAccount,
				className: "login2-back-button"
			}, _pisell_utils.locales.getText("pisell-login2-back")));
		}
		if (currentVerificationMethod === "verification_code" && loginStep === "account") {
			const handleFormSubmit = (e) => {
				e === null || e === void 0 || e.preventDefault();
				handleSendCode();
			};
			return /* @__PURE__ */ react.default.createElement(antd.Form, {
				form,
				layout: "vertical",
				className: "login2-form",
				size: "large"
			}, isEmail && /* @__PURE__ */ react.default.createElement("div", { style: {
				position: "absolute",
				left: "-9999px",
				opacity: 0,
				pointerEvents: "none"
			} }, /* @__PURE__ */ react.default.createElement("input", {
				type: "text",
				name: "username",
				autoComplete: "username",
				tabIndex: -1,
				readOnly: true,
				"aria-hidden": "true"
			})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
				label: accountLabel,
				name: accountFieldName,
				rules: accountRules,
				className: isPhone ? "phone-input-form-item" : "",
				validateTrigger: ["onBlur", "onSubmit"]
			}, isPhone ? /* @__PURE__ */ react.default.createElement(require_PhoneInput.default, {
				size: "large",
				placeholder: accountPlaceholder,
				className: "login2-phone-input",
				countries,
				valueFormat: "object",
				onKeyDown: (e) => {
					if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
						e.preventDefault();
						handleFormSubmit(e);
					}
				}
			}) : /* @__PURE__ */ react.default.createElement(_pisell_materials.Input, {
				size: "large",
				placeholder: accountPlaceholder,
				className: "login2-input",
				type: "email",
				autoComplete: "email",
				onKeyDown: (e) => {
					if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
						e.preventDefault();
						handleFormSubmit(e);
					}
				}
			})), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
				type: "primary",
				size: "large",
				block: true,
				htmlType: "button",
				loading,
				onClick: handleFormSubmit,
				className: "login2-submit-button"
			}, isEmail ? _pisell_utils.locales.getText("pisell-login2-continue-with-email") : _pisell_utils.locales.getText("pisell-login2-continue-with-phone")));
		}
		return /* @__PURE__ */ react.default.createElement(antd.Form, {
			form,
			layout: "vertical",
			className: "login2-form",
			size: "large",
			onFinish: handleLogin
		}, isEmail && /* @__PURE__ */ react.default.createElement("div", { style: {
			position: "absolute",
			left: "-9999px",
			opacity: 0,
			pointerEvents: "none"
		} }, /* @__PURE__ */ react.default.createElement("input", {
			type: "text",
			name: "username",
			autoComplete: "username",
			tabIndex: -1,
			readOnly: true,
			"aria-hidden": "true"
		})), isEmail ? /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			label: accountLabel,
			name: accountFieldName,
			rules: accountRules,
			validateTrigger: ["onBlur", "onSubmit"]
		}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Input, {
			size: "large",
			placeholder: accountPlaceholder,
			className: "login2-input",
			type: "email",
			autoComplete: "email",
			value: getAccountValue() || enteredAccount || "",
			onChange: (e) => {
				const newValue = e.target.value;
				setEnteredAccount(newValue);
				form.setFieldsValue({ [accountFieldName]: newValue });
			}
		})) : /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			label: accountLabel,
			name: accountFieldName,
			rules: accountRules,
			validateTrigger: ["onBlur", "onSubmit"]
		}, /* @__PURE__ */ react.default.createElement(require_PhoneInput.default, {
			size: "large",
			placeholder: accountPlaceholder,
			className: "login2-phone-input",
			countries,
			valueFormat: "object"
		})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			label: ((_config$ui8 = config.ui) === null || _config$ui8 === void 0 || (_config$ui8 = _config$ui8.formLabels) === null || _config$ui8 === void 0 || (_config$ui8 = _config$ui8.password) === null || _config$ui8 === void 0 ? void 0 : _config$ui8.show) !== false ? ((_config$ui9 = config.ui) === null || _config$ui9 === void 0 || (_config$ui9 = _config$ui9.formLabels) === null || _config$ui9 === void 0 || (_config$ui9 = _config$ui9.password) === null || _config$ui9 === void 0 ? void 0 : _config$ui9.text) || _pisell_utils.locales.getText("pisell-login2-password-label") : void 0,
			name: "password",
			rules: passwordValidationRules,
			validateTrigger: ["onBlur", "onSubmit"]
		}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Input.Password, {
			size: "large",
			placeholder: _pisell_utils.locales.getText("pisell-login2-password-placeholder"),
			className: "login2-input",
			name: "password",
			autoComplete: "current-password",
			type: "password"
		})), /* @__PURE__ */ react.default.createElement("div", { className: "login2-form-footer" }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			name: "remember_me",
			valuePropName: "checked",
			noStyle: true
		}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Checkbox, null, _pisell_utils.locales.getText("pisell-login2-remember-me"))), currentVerificationMethod === "password" && /* @__PURE__ */ react.default.createElement("a", {
			className: "login2-link",
			onClick: handleForgotPasswordClick
		}, _pisell_utils.locales.getText("pisell-login2-forgot-password"))), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
			type: "primary",
			size: "large",
			block: true,
			htmlType: "submit",
			loading,
			onClick: handleLogin,
			className: "login2-submit-button"
		}, _pisell_utils.locales.getText("pisell-login2-login-button")));
	};
	const renderSwitchOptions = () => {
		if (!currentLoginMethod) return null;
		const primaryMethod = loginMethods[0];
		const currentIsFormMethod = currentLoginMethod.type === "email" || currentLoginMethod.type === "phone";
		const primaryIsFormMethod = (primaryMethod === null || primaryMethod === void 0 ? void 0 : primaryMethod.type) === "email" || (primaryMethod === null || primaryMethod === void 0 ? void 0 : primaryMethod.type) === "phone";
		const shouldUseFormLayout = currentIsFormMethod || primaryIsFormMethod;
		const verificationSwitchButtons = [];
		if (currentIsFormMethod) (currentLoginMethod.verificationMethods || []).filter((method) => method !== currentVerificationMethod).forEach((method) => {
			if (method === "verification_code") {
				const text = currentLoginMethod.type === "email" ? _pisell_utils.locales.getText("pisell-login2-switch-to-email-code") : _pisell_utils.locales.getText("pisell-login2-switch-to-sms-code");
				verificationSwitchButtons.push(/* @__PURE__ */ react.default.createElement("button", {
					key: "switch-to-code",
					className: "login2-switch-option-button",
					onClick: () => switchVerificationMethod("verification_code")
				}, currentLoginMethod.type === "email" ? /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-mail-01" }) : /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-phone" }), /* @__PURE__ */ react.default.createElement("span", { className: "option-text" }, text)));
			} else verificationSwitchButtons.push(/* @__PURE__ */ react.default.createElement("button", {
				key: "switch-to-password",
				className: "login2-switch-option-button",
				onClick: () => switchVerificationMethod("password")
			}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-key-01" }), /* @__PURE__ */ react.default.createElement("span", { className: "option-text" }, _pisell_utils.locales.getText("pisell-login2-switch-to-password"))));
		});
		const emailPhoneSwitchButtons = [];
		loginMethods.forEach((method, index) => {
			if (method.type === "email" || method.type === "phone") {
				if (method.type === currentLoginMethod.type) return;
				const isLast = isLastLoginMethod(method.type);
				const className = (0, classnames.default)("login2-switch-option-button", { "has-last-login-badge": isLast });
				emailPhoneSwitchButtons.push(/* @__PURE__ */ react.default.createElement("button", {
					key: `${method.type}-${index}`,
					className,
					onClick: () => switchLoginMethod(method)
				}, isLast && /* @__PURE__ */ react.default.createElement("div", { className: "last-login-badge" }, _pisell_utils.locales.getText("pisell-login2-last-login-badge")), /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: method.type === "email" ? "pisell2-mail-01" : "pisell2-phone" }), /* @__PURE__ */ react.default.createElement("span", { className: "option-text" }, method.type === "email" ? _pisell_utils.locales.getText("pisell-login2-switch-to-email") : _pisell_utils.locales.getText("pisell-login2-switch-to-phone"))));
			}
		});
		const nonOauthButtons = [...verificationSwitchButtons, ...emailPhoneSwitchButtons];
		const registerPrompt = onSwitchToRegister && /* @__PURE__ */ react.default.createElement("div", { className: "login2-register-prompt" }, /* @__PURE__ */ react.default.createElement("span", { className: "register-prompt-text" }, _pisell_utils.locales.getText("pisell-login2-no-account")), /* @__PURE__ */ react.default.createElement("button", {
			className: "register-prompt-link",
			onClick: onSwitchToRegister
		}, _pisell_utils.locales.getText("pisell-login2-register-link")));
		if (!nonOauthButtons.length && !oauthProviders.length) return registerPrompt;
		if (shouldUseFormLayout) {
			const groups = [];
			if (nonOauthButtons.length > 0) groups.push(/* @__PURE__ */ react.default.createElement("div", {
				key: "non-oauth",
				className: "login2-switch-options"
			}, nonOauthButtons));
			if (oauthProviders.length > 0) groups.push(/* @__PURE__ */ react.default.createElement(require_OAuthButtonGroup.default, {
				key: "oauth",
				providers: oauthProviders,
				wrapperClassName: "login2-oauth-buttons",
				buttonClassName: "login2-oauth-button",
				gap: 12
			}));
			if (!groups.length) return registerPrompt;
			return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: "login2-divider" }, _pisell_utils.locales.getText("pisell-login2-or")), /* @__PURE__ */ react.default.createElement("div", { className: "login2-switch-groups" }, groups), registerPrompt);
		}
		const primaryProvider = oauthProviders.find((provider) => provider.key === (primaryMethod === null || primaryMethod === void 0 ? void 0 : primaryMethod.type));
		const secondaryOauthProviders = oauthProviders.filter((provider) => provider.key !== (primaryMethod === null || primaryMethod === void 0 ? void 0 : primaryMethod.type));
		const hasSecondaryButtons = nonOauthButtons.length > 0 || secondaryOauthProviders.length > 0;
		return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: "login2-switch-groups" }, primaryProvider ? /* @__PURE__ */ react.default.createElement(require_OAuthButtonGroup.default, {
			providers: [primaryProvider],
			wrapperClassName: "login2-oauth-buttons",
			buttonClassName: "login2-oauth-button",
			gap: 12
		}) : /* @__PURE__ */ react.default.createElement("div", { className: "login2-switch-options" }, /* @__PURE__ */ react.default.createElement("button", {
			key: "primary-fallback",
			className: "login2-switch-option-button",
			onClick: () => {
				if ((primaryMethod === null || primaryMethod === void 0 ? void 0 : primaryMethod.type) === "guest") handleGuestLogin();
				else if ((primaryMethod === null || primaryMethod === void 0 ? void 0 : primaryMethod.type) === "google" || (primaryMethod === null || primaryMethod === void 0 ? void 0 : primaryMethod.type) === "facebook" || (primaryMethod === null || primaryMethod === void 0 ? void 0 : primaryMethod.type) === "apple") handleOAuthClick(primaryMethod.type);
			}
		}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: (primaryMethod === null || primaryMethod === void 0 ? void 0 : primaryMethod.type) === "guest" ? "pisell2-user-01" : (primaryMethod === null || primaryMethod === void 0 ? void 0 : primaryMethod.type) === "google" ? "pisell2-google" : (primaryMethod === null || primaryMethod === void 0 ? void 0 : primaryMethod.type) === "facebook" ? "pisell2-facebook" : "pisell2-apple" }), /* @__PURE__ */ react.default.createElement("span", { className: "option-text" }, (primaryMethod === null || primaryMethod === void 0 ? void 0 : primaryMethod.type) === "guest" ? _pisell_utils.locales.getText("pisell-login2-login-as-guest") : `${_pisell_utils.locales.getText("pisell-login2-continue-with")} ${(primaryMethod === null || primaryMethod === void 0 ? void 0 : primaryMethod.type) ? primaryMethod.type.charAt(0).toUpperCase() + primaryMethod.type.slice(1) : ""}`))), hasSecondaryButtons && /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: "login2-divider" }, _pisell_utils.locales.getText("pisell-login2-or")), nonOauthButtons.length > 0 && /* @__PURE__ */ react.default.createElement("div", { className: "login2-switch-options" }, nonOauthButtons), secondaryOauthProviders.length > 0 && /* @__PURE__ */ react.default.createElement(require_OAuthButtonGroup.default, {
			providers: secondaryOauthProviders,
			wrapperClassName: "login2-oauth-buttons",
			buttonClassName: "login2-oauth-button",
			gap: 12
		}))), registerPrompt);
	};
	if (!visible) return null;
	const { ui } = config;
	if (isEmailLinkVerification) {
		if (emailLinkVerifyStatus === "verifying") return /* @__PURE__ */ react.default.createElement("div", {
			className: (0, classnames.default)("login2-container", className),
			style: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, style), {}, { "--theme-color": (ui === null || ui === void 0 ? void 0 : ui.themeColor) || "#7F56D9" })
		}, /* @__PURE__ */ react.default.createElement("div", { className: "login2-email-link-verifying" }, /* @__PURE__ */ react.default.createElement("div", { className: "verifying-content" }, /* @__PURE__ */ react.default.createElement("div", { className: "verifying-icon" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
			type: "icon-loading",
			spin: true
		})), /* @__PURE__ */ react.default.createElement("h2", { className: "verifying-title" }, "Verifying your email..."), /* @__PURE__ */ react.default.createElement("p", { className: "verifying-desc" }, "Please wait while we verify your email link."))));
		if (emailLinkVerifyStatus === "success") return /* @__PURE__ */ react.default.createElement("div", {
			className: (0, classnames.default)("login2-container", className),
			style: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, style), {}, { "--theme-color": (ui === null || ui === void 0 ? void 0 : ui.themeColor) || "#7F56D9" })
		}, /* @__PURE__ */ react.default.createElement(require_SetPassword.default, {
			scenario: "reset",
			flowData: {
				account: resetPasswordUserEmail || "",
				accountType: "email",
				verificationMethod: "verification_code"
			},
			onSubmit: function() {
				var _ref14 = require_asyncToGenerator._asyncToGenerator(function* (password, confirmPassword) {
					try {
						if (registerAndLogin === null || registerAndLogin === void 0 ? void 0 : registerAndLogin.resetPasswordByCode) {
							const result = yield registerAndLogin.resetPasswordByCode({
								code: config.emailLinkVerification.code,
								password
							});
							if (result.status) {
								antd.message.success(_pisell_utils.locales.getText("pisell-forgot-password-success"));
								setEmailLinkVerifyStatus(null);
								setEmailLinkError("");
								if (resetPasswordUserEmail) {
									const emailMethod = config.loginMethods.find((method) => method.type === "email");
									if (emailMethod) {
										setCurrentLoginMethod(emailMethod);
										setCurrentVerificationMethod(emailMethod.verificationMethods[0]);
									}
									form.setFieldsValue({ email: resetPasswordUserEmail });
									setEnteredAccount(resetPasswordUserEmail);
									setLoginStep("account");
								}
							} else antd.message.error(result.message || _pisell_utils.locales.getText("pisell-forgot-password-failed"));
						} else antd.message.error("系统错误，请稍后重试");
					} catch (error) {
						antd.message.error((error === null || error === void 0 ? void 0 : error.message) || _pisell_utils.locales.getText("pisell-forgot-password-failed"));
					}
				});
				return function(_x13, _x14) {
					return _ref14.apply(this, arguments);
				};
			}(),
			onBack: () => {
				setEmailLinkVerifyStatus(null);
				setEmailLinkError("");
			},
			loading
		}));
		if (emailLinkVerifyStatus === "error") return /* @__PURE__ */ react.default.createElement("div", {
			className: (0, classnames.default)("login2-container", className),
			style: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, style), {}, { "--theme-color": (ui === null || ui === void 0 ? void 0 : ui.themeColor) || "#7F56D9" })
		}, /* @__PURE__ */ react.default.createElement("div", { className: "login2-email-link-error" }, /* @__PURE__ */ react.default.createElement("div", { className: "error-content" }, /* @__PURE__ */ react.default.createElement("div", { className: "error-icon" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "icon-error" })), /* @__PURE__ */ react.default.createElement("h2", { className: "error-title" }, _pisell_utils.locales.getText("pisell-login2-verification-failed-title")), /* @__PURE__ */ react.default.createElement("p", { className: "error-desc" }, emailLinkError), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
			type: "primary",
			size: "large",
			block: true,
			className: "login2-error-main-button",
			onClick: () => {
				setEmailLinkVerifyStatus(null);
				setEmailLinkError("");
			}
		}, _pisell_utils.locales.getText("pisell-login2-login-button")))));
	}
	if (showForgotPassword) {
		const accountType = (currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.type) === "email" ? "email" : "phone";
		return /* @__PURE__ */ react.default.createElement("div", {
			className: (0, classnames.default)("login2-container", className),
			style: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, style), {}, { "--theme-color": (ui === null || ui === void 0 ? void 0 : ui.themeColor) || "#7F56D9" })
		}, /* @__PURE__ */ react.default.createElement(require_ForgotPasswordFlow.default, {
			initialEmail: enteredAccount,
			accountType,
			onSendCode: handleForgotPasswordSendCode,
			onVerifyCode: handleForgotPasswordVerifyCode,
			onResetPassword: isEmailLinkVerification ? handleEmailLinkResetPassword : handleForgotPasswordReset,
			onSendResetLink: handleForgotPasswordSendLink,
			onBack: handleCloseForgotPassword,
			loading,
			countdown,
			countries
		}));
	}
	if (loginStep === "code") {
		const accountType = (currentLoginMethod === null || currentLoginMethod === void 0 ? void 0 : currentLoginMethod.type) === "email" ? "email" : "phone";
		return /* @__PURE__ */ react.default.createElement("div", {
			className: (0, classnames.default)("login2-container", className),
			style: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, style), {}, { "--theme-color": (ui === null || ui === void 0 ? void 0 : ui.themeColor) || "#7F56D9" })
		}, /* @__PURE__ */ react.default.createElement(require_LoginCodeInput.default, {
			account: typeof enteredAccount === "string" ? enteredAccount : enteredAccount.phone,
			accountType,
			codeLength: 4,
			onSubmit: handleCodeSubmit,
			onResend: handleSendCode,
			onBack: handleBackFromCode,
			countdown,
			loading,
			error: codeError,
			onClearError: () => setCodeError("")
		}));
	}
	return /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("login2-container", "register2-container", className),
		style: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, style), {}, { "--theme-color": (ui === null || ui === void 0 ? void 0 : ui.themeColor) || "#7F56D9" })
	}, /* @__PURE__ */ react.default.createElement(require_Header.default, { ui }), /* @__PURE__ */ react.default.createElement("div", { className: "login2-content" }, renderMainLoginForm(), renderSwitchOptions()), /* @__PURE__ */ react.default.createElement(require_LegalTerms.default, { config: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, config.legalTerms), {}, { mode: "login" }) }));
};
//#endregion
exports.default = Login2;
