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/components/authentication/admin/ChannelAuthSetting/PageSetting/index.tsx
var PageSetting_exports = {};
__export(PageSetting_exports, {
  default: () => PageSetting_default
});
module.exports = __toCommonJS(PageSetting_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_classnames = __toESM(require("classnames"));
var import_utils = require("@pisell/utils");
var import_locales = __toESM(require("./locales"));
var import_useEngineContext = __toESM(require("../../../../../hooks/useEngineContext"));
var import_PageSettingItem = __toESM(require("../PageSettingItem"));
var import_PageSetting = require("./PageSetting.less");
var { Title, Paragraph } = import_antd.Typography;
var PageSetting = (0, import_react.forwardRef)(({
  className,
  style,
  value,
  onChange,
  showRegisterPage = true,
  showImageUpload = true
}, ref) => {
  var _a, _b;
  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 registerPageRef = (0, import_react.useRef)(null);
  const loginPageRef = (0, import_react.useRef)(null);
  (0, import_react.useImperativeHandle)(ref, () => ({
    validateFields: async () => {
      const promises = [];
      if (showRegisterPage && registerPageRef.current) {
        promises.push(registerPageRef.current.validateFields());
      }
      if ((!sameAsRegister || !showRegisterPage) && loginPageRef.current) {
        promises.push(loginPageRef.current.validateFields());
      }
      return Promise.all(promises);
    }
  }));
  const [registerPageValue, setRegisterPageValue] = (0, import_react.useState)({
    backgroundImage: void 0,
    termsConditions: []
  });
  const [sameAsRegister, setSameAsRegister] = (0, import_react.useState)(true);
  const [loginPageValue, setLoginPageValue] = (0, import_react.useState)({
    backgroundImage: void 0,
    termsConditions: []
  });
  (0, import_react.useEffect)(() => {
    var _a2;
    if (value) {
      setRegisterPageValue(value.registerPage || {
        backgroundImage: void 0,
        termsConditions: []
      });
      setSameAsRegister(((_a2 = value.loginPage) == null ? void 0 : _a2.sameAsRegister) ?? true);
      setTimeout(() => {
        var _a3;
        setLoginPageValue(((_a3 = value.loginPage) == null ? void 0 : _a3.settings) || {
          backgroundImage: void 0,
          termsConditions: []
        });
      }, 0);
    }
  }, [value]);
  const handleRegisterPageChange = (val) => {
    onChange == null ? void 0 : onChange({
      registerPage: val,
      loginPage: {
        sameAsRegister,
        settings: loginPageValue
      }
    });
  };
  const handleLoginPageChange = (val) => {
    onChange == null ? void 0 : onChange({
      registerPage: registerPageValue,
      loginPage: {
        sameAsRegister,
        settings: val
      }
    });
  };
  const handleSameAsRegisterChange = (checked) => {
    onChange == null ? void 0 : onChange({
      registerPage: registerPageValue,
      loginPage: {
        sameAsRegister: checked,
        settings: loginPageValue
      }
    });
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("page-setting", className), style }, showRegisterPage && /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-group" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-group-header" }, /* @__PURE__ */ import_react.default.createElement(Title, { level: 2, className: "page-setting-group-title" }, import_utils.locales.getText("page.setting.register.title")), /* @__PURE__ */ import_react.default.createElement(Paragraph, { className: "page-setting-group-description" }, import_utils.locales.getText("page.setting.register.description"))), /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-group-content" }, /* @__PURE__ */ import_react.default.createElement(
    import_PageSettingItem.default,
    {
      ref: registerPageRef,
      value: registerPageValue,
      onChange: handleRegisterPageChange,
      showImageUpload
    }
  ))), /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-group" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-group-header" }, /* @__PURE__ */ import_react.default.createElement(Title, { level: 2, className: "page-setting-group-title" }, import_utils.locales.getText("page.setting.login.title")), /* @__PURE__ */ import_react.default.createElement(Paragraph, { className: "page-setting-group-description" }, import_utils.locales.getText("page.setting.login.description"))), /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-group-content" }, showRegisterPage && /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-checkbox" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Checkbox,
    {
      checked: sameAsRegister,
      onChange: (e) => handleSameAsRegisterChange(e.target.checked)
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-checkbox-label" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "page-setting-checkbox-label-text" }, import_utils.locales.getText("page.setting.login.sameAsRegister")), /* @__PURE__ */ import_react.default.createElement("span", { className: "page-setting-checkbox-label-description" }, import_utils.locales.getText("page.setting.login.sameAsRegister.description")))
  )), (!sameAsRegister || !showRegisterPage) && /* @__PURE__ */ import_react.default.createElement(
    import_PageSettingItem.default,
    {
      ref: loginPageRef,
      value: loginPageValue,
      onChange: handleLoginPageChange,
      showImageUpload
    }
  ))));
});
PageSetting.displayName = "PageSetting";
var PageSetting_default = PageSetting;
