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/index.tsx
var ChannelAuthSetting_exports = {};
__export(ChannelAuthSetting_exports, {
  default: () => ChannelAuthSetting_default
});
module.exports = __toCommonJS(ChannelAuthSetting_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_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_PageSetting = __toESM(require("./PageSetting"));
var import_AuthenticationMethods = __toESM(require("./AuthenticationMethods"));
var import_CollectInfo = __toESM(require("./CollectInfo"));
var import_locales = __toESM(require("./locales"));
var import_ChannelAuthSetting = require("./ChannelAuthSetting.less");
var { Title, Paragraph } = import_antd.Typography;
var ChannelAuthSetting = ({
  className,
  style,
  value,
  defaultActiveTab,
  visibleTabs,
  showRegisterPage = true,
  onSave
}) => {
  var _a, _b;
  const context = (0, import_useEngineContext.default)();
  const { useParams } = context.appHelper.utils.getApp().history;
  const params = useParams();
  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");
  console.log("ChannelAuthSetting", params);
  const allTabs = ["pageSetting", "authenticationMethods", "collectInfo"];
  const displayTabs = (0, import_react.useMemo)(() => {
    if (visibleTabs && visibleTabs.length > 0) {
      return allTabs.filter((tab) => visibleTabs.includes(tab));
    }
    return allTabs;
  }, [visibleTabs]);
  const initialActiveTab = (0, import_react.useMemo)(() => {
    if (defaultActiveTab && displayTabs.includes(defaultActiveTab)) {
      return defaultActiveTab;
    }
    return displayTabs[0] || "pageSetting";
  }, [defaultActiveTab, displayTabs]);
  const [activeTab, setActiveTab] = (0, import_react.useState)(initialActiveTab);
  const [internalValue, setInternalValue] = (0, import_react.useState)(
    value || {}
  );
  const pageSettingRef = (0, import_react.useRef)(null);
  (0, import_react.useEffect)(() => {
    if (value) {
      setInternalValue(value);
    }
  }, [value]);
  const handlePageSettingChange = (pageSettingValue) => {
    setInternalValue((prev) => ({
      ...prev,
      pageSetting: pageSettingValue
    }));
  };
  const handleAuthenticationMethodsChange = (authMethodsValue) => {
    setInternalValue((prev) => ({
      ...prev,
      authenticationMethods: authMethodsValue
    }));
  };
  const handleCollectInfoChange = (collectInfoValue) => {
    setInternalValue((prev) => ({
      ...prev,
      collectInfo: collectInfoValue
    }));
  };
  const handleSave = async () => {
    try {
      const validationPromises = [];
      if (activeTab === "pageSetting" && pageSettingRef.current) {
        validationPromises.push(pageSettingRef.current.validateFields());
      }
      if (validationPromises.length > 0) {
        await Promise.all(validationPromises);
      }
      const currentTabData = {};
      if (activeTab === "pageSetting") {
        currentTabData.pageSetting = internalValue.pageSetting;
      } else if (activeTab === "authenticationMethods") {
        currentTabData.authenticationMethods = internalValue.authenticationMethods;
      } else if (activeTab === "collectInfo") {
        currentTabData.collectInfo = internalValue.collectInfo;
      }
      onSave == null ? void 0 : onSave({
        value: currentTabData,
        currentTab: activeTab
      });
    } catch (error) {
      import_antd.message.error(import_utils.locales.getText("channel.auth.setting.validation.error") || "请检查表单填写是否正确");
      console.error("表单校验失败:", error);
    }
  };
  const allTabItems = (0, import_react.useMemo)(() => ({
    pageSetting: {
      key: "pageSetting",
      label: import_utils.locales.getText("channel.auth.setting.tab.pageSetting"),
      children: /* @__PURE__ */ import_react.default.createElement(
        import_PageSetting.default,
        {
          ref: pageSettingRef,
          value: internalValue.pageSetting,
          onChange: handlePageSettingChange,
          showRegisterPage
        }
      )
    },
    authenticationMethods: {
      key: "authenticationMethods",
      label: import_utils.locales.getText("channel.auth.setting.tab.authenticationMethods"),
      children: /* @__PURE__ */ import_react.default.createElement(
        import_AuthenticationMethods.default,
        {
          value: internalValue.authenticationMethods,
          onChange: handleAuthenticationMethodsChange
        }
      )
    },
    collectInfo: {
      key: "collectInfo",
      label: import_utils.locales.getText("channel.auth.setting.tab.collectInfo"),
      children: /* @__PURE__ */ import_react.default.createElement(
        import_CollectInfo.default,
        {
          value: internalValue.collectInfo,
          onChange: handleCollectInfoChange
        }
      )
    }
  }), [internalValue, showRegisterPage]);
  const tabItems = (0, import_react.useMemo)(() => {
    return displayTabs.map((tabKey) => allTabItems[tabKey]);
  }, [displayTabs, allTabItems]);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("channel-auth-setting", className), style }, /* @__PURE__ */ import_react.default.createElement("div", { className: "channel-auth-setting-header" }, /* @__PURE__ */ import_react.default.createElement(Title, { level: 1, className: "channel-auth-setting-title" }, import_utils.locales.getText("channel.auth.setting.title")), /* @__PURE__ */ import_react.default.createElement(Paragraph, { className: "channel-auth-setting-description" }, import_utils.locales.getText("channel.auth.setting.description"))), /* @__PURE__ */ import_react.default.createElement("div", { className: "channel-auth-setting-tabs" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Tabs,
    {
      activeKey: activeTab,
      onChange: setActiveTab,
      items: tabItems
    }
  )), /* @__PURE__ */ import_react.default.createElement("div", { className: "channel-auth-setting-footer" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { type: "primary", onClick: handleSave }, import_utils.locales.getText("channel.auth.setting.button.save"))));
};
var ChannelAuthSetting_default = ChannelAuthSetting;
