const require_runtime = require("../../../_virtual/_rolldown/runtime.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 _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
require("../index.less");
//#region src/plus/saasRegister/components/VertifyEmail.tsx
const COUNTDOWN_NUM = 60;
const VertifyEmail = (props) => {
	const [loading, setLoading] = (0, react.useState)(false);
	const [countdown, setCountdown] = (0, react.useState)(0);
	const countdownRef = (0, react.useRef)(0);
	const timerRef = (0, react.useRef)(null);
	(0, react.useEffect)(() => {
		_onSendEmail();
		return () => {
			timerRef.current && clearInterval(timerRef.current);
			timerRef.current = null;
		};
	}, []);
	const _startCountdown = () => {
		if (timerRef.current) return;
		countdownRef.current = COUNTDOWN_NUM;
		setCountdown(countdownRef.current);
		timerRef.current = setInterval(() => {
			if (countdownRef.current > 0) {
				countdownRef.current = countdownRef.current - 1;
				setCountdown(countdownRef.current);
			} else {
				clearInterval(timerRef.current);
				timerRef.current = null;
			}
		}, 1e3);
	};
	const _onSendEmail = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
			if (countdownRef.current > 0 || loading) return;
			setLoading(true);
			try {
				var _props$onSendEmail;
				yield props === null || props === void 0 || (_props$onSendEmail = props.onSendEmail) === null || _props$onSendEmail === void 0 ? void 0 : _props$onSendEmail.call(props);
				_startCountdown();
			} catch (error) {
				console.error("onResend failed:", error);
			} finally {
				setLoading(false);
			}
		});
		return function _onSendEmail() {
			return _ref.apply(this, arguments);
		};
	}();
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-saas-register-form" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-saas-register-form-main" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-saas-register-form-title" }, _pisell_utils.locales.getText("pisell-saas-register-verify-email-title")), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-saas-register-form-subtitle" }, _pisell_utils.locales.getText("pisell-saas-register-verify-email-subtitle")), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-saas-register-form-email" }, props.email, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
		type: "pisell2-edit-05",
		className: "pisell-saas-register-form-email-icon",
		onClick: props.onEditEmail
	}))), /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-saas-register-action",
		style: {
			marginTop: "32px",
			textAlign: "center"
		}
	}, _pisell_utils.locales.getText("pisell-saas-register-resend-text"), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
		type: "link",
		onClick: _onSendEmail,
		disabled: countdown > 0 || loading,
		className: "pisell-saas-register-link-button"
	}, _pisell_utils.locales.getText("pisell-saas-register-resend-button-text"), /* @__PURE__ */ react.default.createElement("span", { style: { marginLeft: "4px" } }, countdown > 0 && `(${countdown})`))));
};
//#endregion
exports.default = VertifyEmail;
