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/plus/saasRegister/components/VertifyEmail.tsx
var VertifyEmail_exports = {};
__export(VertifyEmail_exports, {
  default: () => VertifyEmail_default
});
module.exports = __toCommonJS(VertifyEmail_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import__ = require("../index.less");
var COUNTDOWN_NUM = 60;
var VertifyEmail = (props) => {
  const [loading, setLoading] = (0, import_react.useState)(false);
  const [countdown, setCountdown] = (0, import_react.useState)(0);
  const countdownRef = (0, import_react.useRef)(0);
  const timerRef = (0, import_react.useRef)(null);
  (0, import_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 = async () => {
    var _a;
    if (countdownRef.current > 0 || loading) {
      return;
    }
    setLoading(true);
    try {
      await ((_a = props == null ? void 0 : props.onSendEmail) == null ? void 0 : _a.call(props));
      _startCountdown();
    } catch (error) {
      console.error("onResend failed:", error);
    } finally {
      setLoading(false);
    }
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-saas-register-form" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-saas-register-form-main" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-saas-register-form-title" }, import_utils.locales.getText("pisell-saas-register-verify-email-title")), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-saas-register-form-subtitle" }, import_utils.locales.getText("pisell-saas-register-verify-email-subtitle")), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-saas-register-form-email" }, props.email, /* @__PURE__ */ import_react.default.createElement(
    import_materials.Iconfont,
    {
      type: "pisell2-edit-05",
      className: "pisell-saas-register-form-email-icon",
      onClick: props.onEditEmail
    }
  ))), /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-saas-register-action",
      style: { marginTop: "32px", textAlign: "center" }
    },
    import_utils.locales.getText("pisell-saas-register-resend-text"),
    /* @__PURE__ */ import_react.default.createElement(
      import_materials.Button,
      {
        type: "link",
        onClick: _onSendEmail,
        disabled: countdown > 0 || loading,
        className: "pisell-saas-register-link-button"
      },
      import_utils.locales.getText("pisell-saas-register-resend-button-text"),
      /* @__PURE__ */ import_react.default.createElement("span", { style: { marginLeft: "4px" } }, countdown > 0 && `(${countdown})`)
    )
  ));
};
var VertifyEmail_default = VertifyEmail;
