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/saasLogin/index.tsx
var saasLogin_exports = {};
__export(saasLogin_exports, {
  default: () => saasLogin_default
});
module.exports = __toCommonJS(saasLogin_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_utils = require("@pisell/utils");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_locales = __toESM(require("./locales"));
var import_utils2 = require("./utils");
var import_index = require("./index.less");
var SaasLogin = (props) => {
  var _a, _b, _c, _d, _e;
  const context = (0, import_useEngineContext.default)();
  import_utils.locales.init(import_locales.default, ((_b = (_a = context == null ? void 0 : context.engine) == null ? void 0 : _a.props) == null ? void 0 : _b.locale) || "en");
  const [form] = import_antd.Form.useForm();
  const [loading, setLoading] = (0, import_react.useState)(false);
  const [data, setData] = (0, import_react.useState)({});
  (0, import_react.useEffect)(() => {
    const newData = (0, import_utils2.mergeData)(import_utils.locales, props);
    setData({ ...newData });
  }, [props, import_utils.locales]);
  const emailRules = [
    {
      required: true,
      message: import_utils.locales.getText("pisell-saas-login-email-error")
    },
    {
      type: "email",
      message: import_utils.locales.getText("pisell-saas-login-email-error-valid")
    }
  ];
  const handleEmailLogin = async () => {
    var _a2;
    try {
      setLoading(true);
      const values = await form.validateFields();
      await ((_a2 = props == null ? void 0 : props.onLogin) == null ? void 0 : _a2.call(props, { ...values, loginMethod: "email" }));
    } catch (error) {
      console.error("Validation failed:", error);
    } finally {
      setLoading(false);
    }
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-saas-login-main" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-saas-login-container" }, (data == null ? void 0 : data.showLogo) && /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `pisell-saas-login-logo ${data.logoPosition}`,
      style: {
        width: ((_c = data == null ? void 0 : data.logoSize) == null ? void 0 : _c.width) || 48,
        height: ((_d = data == null ? void 0 : data.logoSize) == null ? void 0 : _d.height) || 48
      }
    },
    (data == null ? void 0 : data.logo) && /* @__PURE__ */ import_react.default.createElement(
      "img",
      {
        src: data == null ? void 0 : data.logo,
        alt: "logo",
        style: {
          height: ((_e = data == null ? void 0 : data.logoSize) == null ? void 0 : _e.height) || 48
        }
      }
    )
  ), (data == null ? void 0 : data.showWelcomeMessage) && /* @__PURE__ */ import_react.default.createElement(
    "h1",
    {
      className: "pisell-saas-login-welcome-message",
      style: { textAlign: data == null ? void 0 : data.welcomeMessageAlign }
    },
    (data == null ? void 0 : data.welcomeMessage) || ""
  ), (data == null ? void 0 : data.showTitle) && /* @__PURE__ */ import_react.default.createElement(
    "h1",
    {
      className: "pisell-saas-login-title",
      style: { textAlign: data == null ? void 0 : data.titleAlign }
    },
    (data == null ? void 0 : data.title) || ""
  ), (data == null ? void 0 : data.showSubtitle) && /* @__PURE__ */ import_react.default.createElement(
    "p",
    {
      className: "pisell-saas-login-subtitle",
      style: { textAlign: data == null ? void 0 : data.subtitleAlign }
    },
    (data == null ? void 0 : data.subtitle) || ""
  ), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-saas-login-form" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Form, { form }, /* @__PURE__ */ import_react.default.createElement("div", { className: "form-item-label" }, (data == null ? void 0 : data.emailLabel) || ""), /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { name: "email", rules: emailRules }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Input,
    {
      placeholder: (data == null ? void 0 : data.emailPlaceholder) || "",
      size: "large",
      className: "pisell-saas-login-input"
    }
  )), /* @__PURE__ */ import_react.default.createElement("div", { className: "form-item-label" }, (data == null ? void 0 : data.passwordLabel) || ""), /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      name: "password",
      rules: [
        {
          required: true,
          message: import_utils.locales.getText(
            "pisell-saas-login-password-required"
          )
        }
      ]
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.Input.Password,
      {
        placeholder: (data == null ? void 0 : data.passwordPlaceholder) || "",
        size: "large",
        className: "pisell-saas-login-input"
      }
    )
  ), /* @__PURE__ */ import_react.default.createElement(
    import_antd.Button,
    {
      type: "primary",
      block: true,
      size: "large",
      loading,
      onClick: handleEmailLogin,
      className: "pisell-saas-login-button"
    },
    (data == null ? void 0 : data.buttonText) || ""
  ))), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-saas-login-footer" }, (data == null ? void 0 : data.showRegister) && /* @__PURE__ */ import_react.default.createElement(
    "p",
    {
      className: "pisell-saas-login-signup",
      style: { textAlign: data == null ? void 0 : data.registerAlign }
    },
    (data == null ? void 0 : data.showRegisterText) ? data == null ? void 0 : data.registerText : "",
    (data == null ? void 0 : data.showRegisterLinkText) && /* @__PURE__ */ import_react.default.createElement(
      "a",
      {
        onClick: props == null ? void 0 : props.onGoRegister,
        className: "pisell-saas-login-signup-link"
      },
      (data == null ? void 0 : data.registerLinkText) || ""
    )
  ))));
};
var saasLogin_default = SaasLogin;
