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/systemSettings/registry/components/SectionList.tsx
var SectionList_exports = {};
__export(SectionList_exports, {
  default: () => SectionList_default
});
module.exports = __toCommonJS(SectionList_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_icons = require("@ant-design/icons");
var import_icon = require("@pisell/icon");
var import_utils = require("@pisell/utils");
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var getLocalizedText = (text, locale = "zh-CN") => {
  if (typeof text === "string") {
    return text;
  }
  return text[locale] || text.original || text.en || "";
};
var sectionIcons = {
  order: /* @__PURE__ */ import_react.default.createElement(import_icons.ShoppingCartOutlined, null),
  payment: /* @__PURE__ */ import_react.default.createElement(import_icons.CreditCardOutlined, null),
  auth: /* @__PURE__ */ import_react.default.createElement(import_icons.SafetyCertificateOutlined, null),
  default: /* @__PURE__ */ import_react.default.createElement(import_icons.SettingOutlined, null)
};
var renderSectionIcon = (iconName, code) => {
  if (iconName === "pisell2-shopping-cart-01") {
    return /* @__PURE__ */ import_react.default.createElement(import_icon.ShoppingCart01, null);
  }
  if (code && sectionIcons[code]) {
    return sectionIcons[code];
  }
  return sectionIcons.default;
};
var SectionList = ({
  sections,
  selectedSectionId,
  onSectionSelect,
  loading = false,
  hasMore = false,
  onLoadMore
}) => {
  var _a, _b;
  const scrollContainerRef = (0, import_react.useRef)(null);
  const loadingRef = (0, import_react.useRef)(null);
  const context = (0, import_useEngineContext.default)();
  const currentLocale = ((_b = (_a = context == null ? void 0 : context.engine) == null ? void 0 : _a.props) == null ? void 0 : _b.locale) || localStorage.getItem("umi_locale") || "en";
  const handleScroll = (0, import_react.useCallback)(() => {
    if (!scrollContainerRef.current || !hasMore || loading || !onLoadMore) {
      return;
    }
    const container = scrollContainerRef.current;
    const scrollTop = container.scrollTop;
    const scrollHeight = container.scrollHeight;
    const clientHeight = container.clientHeight;
    if (scrollHeight - scrollTop - clientHeight < 100) {
      onLoadMore();
    }
  }, [hasMore, loading, onLoadMore]);
  (0, import_react.useEffect)(() => {
    const container = scrollContainerRef.current;
    if (!container) return;
    container.addEventListener("scroll", handleScroll);
    return () => {
      container.removeEventListener("scroll", handleScroll);
    };
  }, [handleScroll]);
  (0, import_react.useEffect)(() => {
    if (!loadingRef.current || !hasMore || !onLoadMore) return;
    const observer = new IntersectionObserver(
      (entries) => {
        const entry = entries[0];
        if (entry.isIntersecting && !loading) {
          onLoadMore();
        }
      },
      {
        threshold: 0.1
      }
    );
    observer.observe(loadingRef.current);
    return () => {
      observer.disconnect();
    };
  }, [hasMore, loading, onLoadMore]);
  if (sections.length === 0) {
    return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-settings-registry-sections-empty" }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Empty,
      {
        description: import_utils.locales.getText("registry.sections.empty"),
        image: import_antd.Empty.PRESENTED_IMAGE_SIMPLE
      }
    ));
  }
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-settings-registry-sections",
      ref: scrollContainerRef,
      style: {
        height: "100%",
        overflowY: "auto",
        paddingRight: "8px"
      }
    },
    sections.map((section) => /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        key: section.id,
        onClick: () => onSectionSelect(section.id),
        style: { cursor: "pointer" }
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Card,
        {
          className: `pisell-settings-registry-section-card ${selectedSectionId === section.id ? "active" : ""}`,
          hoverable: true,
          bodyStyle: { padding: "16px" }
        },
        /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-settings-registry-section-content" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-settings-registry-section-icon" }, renderSectionIcon(section.icon, section.code)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-settings-registry-section-info" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-settings-registry-section-name" }, getLocalizedText(section.name, currentLocale)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-settings-registry-section-code" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "section-code-tag", style: {
          backgroundColor: "#1890ff",
          color: "white",
          padding: "2px 8px",
          borderRadius: "4px",
          fontSize: "12px"
        } }, section.code)), section.description && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-settings-registry-section-description" }, getLocalizedText(section.description, currentLocale))))
      )
    )),
    hasMore && /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        ref: loadingRef,
        className: "pisell-settings-registry-sections-loading",
        style: {
          textAlign: "center",
          padding: "16px",
          minHeight: "50px"
        }
      },
      loading ? /* @__PURE__ */ import_react.default.createElement(import_antd.Spin, { size: "small" }) : /* @__PURE__ */ import_react.default.createElement("div", { style: { color: "#999" } }, import_utils.locales.getText("registry.sections.loadMore"))
    ),
    !hasMore && sections.length > 0 && /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-settings-registry-sections-no-more",
        style: {
          textAlign: "center",
          padding: "16px",
          color: "#999",
          fontSize: "12px"
        }
      },
      import_utils.locales.getText("registry.sections.noMore")
    )
  );
};
var SectionList_default = SectionList;
