import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import Pagination$1 from "../Pagination/index.js";
import React, { useMemo, useRef } from "react";
import { getUniqueId } from "@pisell/utils";
import { List, Skeleton } from "antd";
import { DoubleRightOutlined } from "@ant-design/icons";
import classNames from "classnames";
import { useScroll } from "ahooks";
import InfiniteScroll from "react-infinite-scroll-component";
import "./index.less";
//#region src/components/list/index.tsx
const _excluded = [
	"className",
	"paginationType",
	"pagination",
	"footer",
	"header",
	"listHeight",
	"loadMoreData",
	"arrow"
];
const prefix = "pisell-lowcode-";
const downArrow = /* @__PURE__ */ React.createElement("div", { className: `${prefix}list-arrow-wrap ${prefix}list-arrow-down` }, /* @__PURE__ */ React.createElement(DoubleRightOutlined, { style: { transform: "rotate(90deg)" } }));
const upArrow = /* @__PURE__ */ React.createElement("div", { className: `${prefix}list-arrow-wrap ${prefix}list-arrow-up` }, /* @__PURE__ */ React.createElement(DoubleRightOutlined, { style: { transform: "rotate(-90deg)" } }));
const List$1 = (props) => {
	const { className, paginationType, pagination, footer, header, listHeight, loadMoreData, arrow } = props, others = _objectWithoutProperties(props, _excluded);
	const listRef = useRef(null);
	const scrollListId = useMemo(() => {
		return `scrollableDiv-${getUniqueId()}`;
	}, []);
	const position = useScroll(listRef);
	const isShowDownArrow = useMemo(() => {
		var _listRef$current, _listRef$current2;
		return arrow && (listRef === null || listRef === void 0 ? void 0 : listRef.current) && ((position === null || position === void 0 ? void 0 : position.top) || 0) + (listRef === null || listRef === void 0 || (_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.clientHeight) < ((_listRef$current2 = listRef.current) === null || _listRef$current2 === void 0 ? void 0 : _listRef$current2.scrollHeight);
	}, [position, arrow]);
	const isShowUpArrow = useMemo(() => {
		return arrow && ((position === null || position === void 0 ? void 0 : position.top) || 0) > 0;
	}, [position, arrow]);
	const _footer = useMemo(() => {
		if (!(pagination && paginationType === "default") && !footer) return null;
		return /* @__PURE__ */ React.createElement(React.Fragment, null, pagination && paginationType === "default" && /* @__PURE__ */ React.createElement(Pagination$1, _objectSpread2({ showLessItems: true }, pagination)), footer);
	}, [pagination, footer]);
	return useMemo(() => {
		var _props$grid2;
		if (paginationType === "scroll") {
			var _props$grid;
			return /* @__PURE__ */ React.createElement("div", { className: `${prefix}scroll-list-wrap` }, header && /* @__PURE__ */ React.createElement("div", { className: `${prefix}scroll-header-wrap` }, header), /* @__PURE__ */ React.createElement("div", {
				id: scrollListId,
				ref: listRef,
				style: {
					height: listHeight || 400,
					overflow: "auto"
				}
			}, isShowUpArrow && upArrow, /* @__PURE__ */ React.createElement(InfiniteScroll, {
				key: `${document.getElementById(scrollListId)}`,
				dataLength: props.dataSource.length,
				next: loadMoreData,
				hasMore: props.dataSource.length < ((pagination === null || pagination === void 0 ? void 0 : pagination.total) || 999999),
				loader: props.dataSource.length > 0 && /* @__PURE__ */ React.createElement(Skeleton, {
					avatar: true,
					paragraph: { rows: 1 },
					active: true,
					className: `${prefix}scroll-skeleton`
				}),
				scrollableTarget: scrollListId
			}, /* @__PURE__ */ React.createElement(List, _objectSpread2(_objectSpread2({}, others), {}, { className: classNames(className, { [`${prefix}list-one-line-wrap`]: props === null || props === void 0 || (_props$grid = props.grid) === null || _props$grid === void 0 ? void 0 : _props$grid.oneLine }) }))), isShowDownArrow && downArrow), _footer && /* @__PURE__ */ React.createElement("div", { className: `${prefix}scroll-footer-wrap` }, _footer));
		}
		return /* @__PURE__ */ React.createElement(List, _objectSpread2(_objectSpread2({}, props), {}, { className: classNames(className, { [`${prefix}list-one-line-wrap`]: props === null || props === void 0 || (_props$grid2 = props.grid) === null || _props$grid2 === void 0 ? void 0 : _props$grid2.oneLine }) }));
	}, [
		props,
		_footer,
		isShowDownArrow,
		isShowUpArrow,
		scrollListId
	]);
};
List$1.Item = List.Item;
//#endregion
export { List$1 as default };
