const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_objectWithoutProperties = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_index = require("../Pagination/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let antd = require("antd");
let _ant_design_icons = require("@ant-design/icons");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let ahooks = require("ahooks");
let react_infinite_scroll_component = require("react-infinite-scroll-component");
react_infinite_scroll_component = require_runtime.__toESM(react_infinite_scroll_component);
require("./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.default.createElement("div", { className: `${prefix}list-arrow-wrap ${prefix}list-arrow-down` }, /* @__PURE__ */ react.default.createElement(_ant_design_icons.DoubleRightOutlined, { style: { transform: "rotate(90deg)" } }));
const upArrow = /* @__PURE__ */ react.default.createElement("div", { className: `${prefix}list-arrow-wrap ${prefix}list-arrow-up` }, /* @__PURE__ */ react.default.createElement(_ant_design_icons.DoubleRightOutlined, { style: { transform: "rotate(-90deg)" } }));
const List = (props) => {
	const { className, paginationType, pagination, footer, header, listHeight, loadMoreData, arrow } = props, others = require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
	const listRef = (0, react.useRef)(null);
	const scrollListId = (0, react.useMemo)(() => {
		return `scrollableDiv-${(0, _pisell_utils.getUniqueId)()}`;
	}, []);
	const position = (0, ahooks.useScroll)(listRef);
	const isShowDownArrow = (0, react.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 = (0, react.useMemo)(() => {
		return arrow && ((position === null || position === void 0 ? void 0 : position.top) || 0) > 0;
	}, [position, arrow]);
	const _footer = (0, react.useMemo)(() => {
		if (!(pagination && paginationType === "default") && !footer) return null;
		return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, pagination && paginationType === "default" && /* @__PURE__ */ react.default.createElement(require_index.default, require_objectSpread2._objectSpread2({ showLessItems: true }, pagination)), footer);
	}, [pagination, footer]);
	return (0, react.useMemo)(() => {
		var _props$grid2;
		if (paginationType === "scroll") {
			var _props$grid;
			return /* @__PURE__ */ react.default.createElement("div", { className: `${prefix}scroll-list-wrap` }, header && /* @__PURE__ */ react.default.createElement("div", { className: `${prefix}scroll-header-wrap` }, header), /* @__PURE__ */ react.default.createElement("div", {
				id: scrollListId,
				ref: listRef,
				style: {
					height: listHeight || 400,
					overflow: "auto"
				}
			}, isShowUpArrow && upArrow, /* @__PURE__ */ react.default.createElement(react_infinite_scroll_component.default, {
				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.default.createElement(antd.Skeleton, {
					avatar: true,
					paragraph: { rows: 1 },
					active: true,
					className: `${prefix}scroll-skeleton`
				}),
				scrollableTarget: scrollListId
			}, /* @__PURE__ */ react.default.createElement(antd.List, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, others), {}, { className: (0, classnames.default)(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.default.createElement("div", { className: `${prefix}scroll-footer-wrap` }, _footer));
		}
		return /* @__PURE__ */ react.default.createElement(antd.List, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, { className: (0, classnames.default)(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.Item = antd.List.Item;
//#endregion
exports.default = List;
