const require_runtime = require("../../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_platform = require("../../../../../utils/platform.js");
const require_useGenGridProps = require("./useGenGridProps.js");
const require_useGapSize = require("./useGapSize.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let react_window = require("react-window");
let react_virtualized_auto_sizer = require("react-virtualized-auto-sizer");
react_virtualized_auto_sizer = require_runtime.__toESM(react_virtualized_auto_sizer);
require("./index.less");
//#region src/components/table/Gallery/components/VirtualGrid/index.tsx
const Cell = (props) => {
	const { columnIndex, rowIndex, style, isScrolling, data } = props;
	const { renderItem, gap, columnCount, dataSource, paddingTop } = data;
	const dataIndex = (0, react.useMemo)(() => {
		return columnCount * rowIndex + columnIndex;
	}, [
		columnCount,
		rowIndex,
		columnIndex
	]);
	const { horizontal, vertical } = require_useGapSize.default(gap);
	const content = (0, react.useMemo)(() => {
		if (dataIndex >= dataSource.length) return null;
		return renderItem(dataSource[dataIndex], dataIndex);
	}, [
		dataSource,
		dataIndex,
		renderItem
	]);
	return /* @__PURE__ */ react.default.createElement("div", { style: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, style), {}, {
		left: ((style === null || style === void 0 ? void 0 : style.left) || 0) + columnIndex * horizontal,
		top: ((style === null || style === void 0 ? void 0 : style.top) || 0) + paddingTop,
		paddingBottom: vertical
	}) }, content);
};
const GridComponent = (props) => {
	const { dataSource, width, height, renderItem, gap, itemMaxWidth, itemMinWidth, rowHeight, paddingTop } = props;
	const { horizontal, vertical } = require_useGapSize.default(gap);
	const { columnCount, columnWidth, rowCount } = require_useGenGridProps.default({
		itemMinWidth,
		itemMaxWidth,
		width,
		dataSource,
		horizontal,
		vertical
	});
	const itemData = (0, react.useMemo)(() => {
		return {
			dataSource,
			renderItem,
			columnCount,
			gap,
			paddingTop
		};
	}, [
		dataSource,
		columnCount,
		gap,
		renderItem,
		paddingTop
	]);
	return /* @__PURE__ */ react.default.createElement(react_window.FixedSizeGrid, {
		className: require_platform.isMobile() ? "pisell-lowcode-mobile-gallery" : "",
		columnCount,
		columnWidth,
		height,
		rowCount,
		rowHeight: rowHeight + vertical,
		width,
		itemData
	}, Cell);
};
const VirtualGrid = (props) => {
	const { dataSource, renderItem, gap, itemMinWidth, itemMaxWidth, rowHeight, paddingTop = 0 } = props;
	if (dataSource.length === 0) return /* @__PURE__ */ react.default.createElement(antd.Empty, {
		style: { marginTop: 32 },
		image: antd.Empty.PRESENTED_IMAGE_SIMPLE
	});
	return /* @__PURE__ */ react.default.createElement(react_virtualized_auto_sizer.default, null, ({ height, width }) => /* @__PURE__ */ react.default.createElement(GridComponent, {
		paddingTop,
		rowHeight,
		itemMinWidth,
		itemMaxWidth,
		gap,
		width,
		height,
		dataSource,
		renderItem
	}));
};
//#endregion
exports.default = VirtualGrid;
