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/list/index.tsx
var list_exports = {};
__export(list_exports, {
  default: () => list_default
});
module.exports = __toCommonJS(list_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_antd = require("antd");
var import_utils = require("@pisell/utils");
var import_react_infinite_scroll_component = __toESM(require("react-infinite-scroll-component"));
var import_icons = require("@ant-design/icons");
var import_ahooks = require("ahooks");
var import_Pagination = __toESM(require("../Pagination"));
var import_index = require("./index.less");
var prefix = "pisell-lowcode-";
var downArrow = /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}list-arrow-wrap ${prefix}list-arrow-down` }, /* @__PURE__ */ import_react.default.createElement(import_icons.DoubleRightOutlined, { style: { transform: "rotate(90deg)" } }));
var upArrow = /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}list-arrow-wrap ${prefix}list-arrow-up` }, /* @__PURE__ */ import_react.default.createElement(import_icons.DoubleRightOutlined, { style: { transform: "rotate(-90deg)" } }));
var List = (props) => {
  const {
    className,
    paginationType,
    pagination,
    footer,
    header,
    listHeight,
    loadMoreData,
    arrow,
    ...others
  } = props;
  const listRef = (0, import_react.useRef)(null);
  const scrollListId = (0, import_react.useMemo)(() => {
    return `scrollableDiv-${(0, import_utils.getUniqueId)()}`;
  }, []);
  const position = (0, import_ahooks.useScroll)(listRef);
  const isShowDownArrow = (0, import_react.useMemo)(() => {
    var _a, _b;
    return arrow && (listRef == null ? void 0 : listRef.current) && ((position == null ? void 0 : position.top) || 0) + ((_a = listRef == null ? void 0 : listRef.current) == null ? void 0 : _a.clientHeight) < ((_b = listRef.current) == null ? void 0 : _b.scrollHeight);
  }, [position, arrow]);
  const isShowUpArrow = (0, import_react.useMemo)(() => {
    return arrow && ((position == null ? void 0 : position.top) || 0) > 0;
  }, [position, arrow]);
  const _footer = (0, import_react.useMemo)(() => {
    if (!(pagination && paginationType === "default") && !footer) {
      return null;
    }
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, pagination && paginationType === "default" && /* @__PURE__ */ import_react.default.createElement(import_Pagination.default, { showLessItems: true, ...pagination }), footer);
  }, [pagination, footer]);
  const list = (0, import_react.useMemo)(() => {
    var _a, _b;
    if (paginationType === "scroll") {
      return /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}scroll-list-wrap` }, header && /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}scroll-header-wrap` }, header), /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          id: scrollListId,
          ref: listRef,
          style: {
            height: listHeight || 400,
            overflow: "auto"
          }
        },
        isShowUpArrow && upArrow,
        /* @__PURE__ */ import_react.default.createElement(
          import_react_infinite_scroll_component.default,
          {
            key: `${document.getElementById(scrollListId)}`,
            dataLength: props.dataSource.length,
            next: loadMoreData,
            hasMore: props.dataSource.length < ((pagination == null ? void 0 : pagination.total) || 999999),
            loader: props.dataSource.length > 0 && /* @__PURE__ */ import_react.default.createElement(
              import_antd.Skeleton,
              {
                avatar: true,
                paragraph: { rows: 1 },
                active: true,
                className: `${prefix}scroll-skeleton`
              }
            ),
            scrollableTarget: scrollListId
          },
          /* @__PURE__ */ import_react.default.createElement(
            import_antd.List,
            {
              ...others,
              className: (0, import_classnames.default)(className, {
                [`${prefix}list-one-line-wrap`]: (_a = props == null ? void 0 : props.grid) == null ? void 0 : _a.oneLine
              })
            }
          )
        ),
        isShowDownArrow && downArrow
      ), _footer && /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}scroll-footer-wrap` }, _footer));
    }
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.List,
      {
        ...props,
        className: (0, import_classnames.default)(className, {
          [`${prefix}list-one-line-wrap`]: (_b = props == null ? void 0 : props.grid) == null ? void 0 : _b.oneLine
        })
      }
    );
  }, [props, _footer, isShowDownArrow, isShowUpArrow, scrollListId]);
  return list;
};
List.Item = import_antd.List.Item;
var list_default = List;
