const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_index = require("../../locales/index.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");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _ant_design_icons = require("@ant-design/icons");
require("./index.less");
//#region src/components/login-and-register/index.tsx
/**
* Saas登录组件
* @param props - 组件属性
* @returns React组件
*/
const loginAndRegister = ({ showLogo = true, logo, logoPosition = "center", logoSize = {
	width: 48,
	height: 48
}, title = require_index.getText("Log in to your account"), showTitle = false, titleAlign = "center", subtitle = require_index.getText("pisell-login-and-register-subtit"), showSubtitle = false, subtitleAlign = "center", loginMethods = [
	"email",
	"google",
	"facebook",
	"apple"
], defaultLoginMethod = "email", emailLabel = require_index.getText("pisell-login-and-register-email-label"), passwordLabel = require_index.getText("pisell-login-and-register-password-label"), emailPlaceholder = require_index.getText("pisell-login-and-register-email-placeholder"), passwordPlaceholder = require_index.getText("pisell-login-and-register-password-placeholder"), emailRules = [{
	required: true,
	message: require_index.getText("pisell-login-and-register-email-error")
}, {
	type: "email",
	message: require_index.getText("pisell-login-and-register-email-error-valid")
}], buttonText = require_index.getText("Log in"), socialLoginTexts = {
	google: require_index.getText("pisell-login-and-register-google"),
	facebook: require_index.getText("pisell-login-and-register-facebook"),
	apple: require_index.getText("pisell-login-and-register-apple")
}, showFooter = true, showSignUp = true, signUpText = require_index.getText("pisell-login-and-register-sign-up"), signUpLink = "", signUpPosition = "center", otherLinks = [], otherLinksPosition = "center", showTabs = true, loginTabText = require_index.getText("pisell-login-and-register-login-tab"), registerTabText = require_index.getText("pisell-login-and-register-register-tab"), registerEmailPlaceholder = require_index.getText("pisell-login-and-register-register-email-placeholder"), registerPasswordPlaceholder = require_index.getText("pisell-login-and-register-register-password-placeholder"), registerButtonText = require_index.getText("pisell-login-and-register-register-button-text"), rememberMeText = require_index.getText("pisell-login-and-register-remember-me"), forgotPasswordText = require_index.getText("pisell-login-and-register-forgot-password"), showRememberMe = false, showForgotPassword = false, onLogin, onSocialLogin, onSignUp, onRegister, backgroundImage = "/login-illustration.png" }) => {
	const [form] = antd.Form.useForm();
	const [loading, setLoading] = (0, react.useState)(false);
	const [activeTab, setActiveTab] = (0, react.useState)("login");
	(0, react.useEffect)(() => {
		document.body.id = "body";
	}, []);
	/**
	* 处理邮箱登录
	*/
	const handleEmailLogin = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
			try {
				setLoading(true);
				const values = yield form.validateFields();
				yield onLogin === null || onLogin === void 0 ? void 0 : onLogin(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, values), {}, { loginMethod: "email" }));
			} catch (error) {
				console.error("Validation failed:", error);
			} finally {
				setLoading(false);
			}
		});
		return function handleEmailLogin() {
			return _ref.apply(this, arguments);
		};
	}();
	/**
	* 处理社交登录
	* @param type - 社交登录类型
	*/
	const handleSocialLogin = (type) => {
		onSocialLogin === null || onSocialLogin === void 0 || onSocialLogin(type);
	};
	/**
	* 处理注册提交
	*/
	const handleRegister = function() {
		var _ref2 = require_asyncToGenerator._asyncToGenerator(function* () {
			try {
				setLoading(true);
				const values = yield form.validateFields();
				yield onRegister === null || onRegister === void 0 ? void 0 : onRegister(values);
			} catch (error) {
				console.error("Validation failed:", error);
			} finally {
				setLoading(false);
			}
		});
		return function handleRegister() {
			return _ref2.apply(this, arguments);
		};
	}();
	return /* @__PURE__ */ react.default.createElement("div", { className: "saas-login-main" }, /* @__PURE__ */ react.default.createElement("div", { className: "saas-login-container" }, showLogo && /* @__PURE__ */ react.default.createElement("div", { className: `saas-login-logo ${logoPosition}` }, logo && /* @__PURE__ */ react.default.createElement("img", {
		src: logo,
		alt: "logo"
	})), showTitle && /* @__PURE__ */ react.default.createElement("h1", {
		className: "saas-login-title",
		style: { textAlign: titleAlign }
	}, title), showSubtitle && /* @__PURE__ */ react.default.createElement("p", {
		className: "saas-login-subtitle",
		style: { textAlign: subtitleAlign }
	}, subtitle), showTabs && /* @__PURE__ */ react.default.createElement("div", { className: "saas-login-tabs" }, /* @__PURE__ */ react.default.createElement("div", {
		className: `tab ${activeTab === "login" ? "active" : ""}`,
		onClick: () => setActiveTab("login")
	}, loginTabText), /* @__PURE__ */ react.default.createElement("div", {
		className: `tab ${activeTab === "register" ? "active" : ""}`,
		onClick: () => setActiveTab("register")
	}, registerTabText)), /* @__PURE__ */ react.default.createElement("div", { className: "saas-login-form" }, activeTab === "login" ? /* @__PURE__ */ react.default.createElement(antd.Form, { form }, /* @__PURE__ */ react.default.createElement("div", { className: "form-item-label" }, emailLabel), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		name: "email",
		rules: emailRules
	}, /* @__PURE__ */ react.default.createElement(antd.Input, {
		placeholder: emailPlaceholder,
		size: "large",
		className: "saas-login-input"
	})), /* @__PURE__ */ react.default.createElement("div", { className: "form-item-label" }, passwordLabel), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		name: "password",
		rules: [{
			required: true,
			message: require_index.getText("pisell-login-and-register-register-password-error")
		}]
	}, /* @__PURE__ */ react.default.createElement(antd.Input.Password, {
		placeholder: passwordPlaceholder,
		size: "large",
		className: "saas-login-input"
	})), (showRememberMe || showForgotPassword) && /* @__PURE__ */ react.default.createElement("div", { className: "saas-login-options" }, showRememberMe && /* @__PURE__ */ react.default.createElement(antd.Checkbox, null, rememberMeText), showForgotPassword && /* @__PURE__ */ react.default.createElement("a", { className: "forgot-password" }, forgotPasswordText)), /* @__PURE__ */ react.default.createElement(antd.Button, {
		type: "primary",
		block: true,
		size: "large",
		loading,
		onClick: handleEmailLogin,
		className: "saas-login-button"
	}, require_index.getText("pisell-login-and-register-login"))) : /* @__PURE__ */ react.default.createElement(antd.Form, { form }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		name: "email",
		rules: emailRules
	}, /* @__PURE__ */ react.default.createElement(antd.Input, {
		placeholder: registerEmailPlaceholder,
		size: "large",
		className: "saas-login-input"
	})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		name: "password",
		rules: [{
			required: true,
			message: require_index.getText("pisell-login-and-register-register-password-error")
		}, {
			min: 6,
			message: require_index.getText("pisell-login-and-register-register-password-error-valid")
		}]
	}, /* @__PURE__ */ react.default.createElement(antd.Input.Password, {
		placeholder: registerPasswordPlaceholder,
		size: "large",
		className: "saas-login-input"
	})), /* @__PURE__ */ react.default.createElement(antd.Button, {
		type: "primary",
		block: true,
		size: "large",
		loading,
		onClick: handleRegister,
		className: "saas-login-button"
	}, registerButtonText)), /* @__PURE__ */ react.default.createElement(antd.Space, {
		direction: "vertical",
		className: "saas-login-social"
	}, loginMethods.includes("google") && /* @__PURE__ */ react.default.createElement(antd.Button, {
		block: true,
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.GoogleOutlined, null),
		className: "saas-login-social-button google",
		onClick: () => handleSocialLogin("google")
	}, socialLoginTexts.google), loginMethods.includes("facebook") && /* @__PURE__ */ react.default.createElement(antd.Button, {
		block: true,
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.FacebookOutlined, null),
		className: "saas-login-social-button facebook",
		onClick: () => handleSocialLogin("facebook")
	}, socialLoginTexts.facebook), loginMethods.includes("apple") && /* @__PURE__ */ react.default.createElement(antd.Button, {
		block: true,
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.AppleOutlined, null),
		className: "saas-login-social-button apple",
		onClick: () => handleSocialLogin("apple")
	}, socialLoginTexts.apple))), showFooter && /* @__PURE__ */ react.default.createElement("div", { className: "saas-login-footer" }, showSignUp && /* @__PURE__ */ react.default.createElement("p", { className: "saas-login-signup" }, signUpText, signUpLink ? /* @__PURE__ */ react.default.createElement("a", { href: signUpLink }, signUpText) : /* @__PURE__ */ react.default.createElement("a", { onClick: onSignUp }, signUpText)), otherLinks.length > 0 && /* @__PURE__ */ react.default.createElement("div", { className: "saas-login-links" }, otherLinks.map((link, index) => /* @__PURE__ */ react.default.createElement("a", {
		key: index,
		href: link.url,
		target: "_blank",
		rel: "noopener noreferrer"
	}, link.text))))));
};
//#endregion
exports.default = loginAndRegister;
