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/table/Gallery/components/VirtualGrid/index.tsx
var VirtualGrid_exports = {};
__export(VirtualGrid_exports, {
  default: () => VirtualGrid_default
});
module.exports = __toCommonJS(VirtualGrid_exports);
var import_react = __toESM(require("react"));
var import_react_window = require("react-window");
var import_react_virtualized_auto_sizer = __toESM(require("react-virtualized-auto-sizer"));
var import_useGenGridProps = __toESM(require("./useGenGridProps"));
var import_useGapSize = __toESM(require("./useGapSize"));
var import_antd = require("antd");
var import_platform = require("../../../../../utils/platform");
var import_index = require("./index.less");
var Cell = (props) => {
  const { columnIndex, rowIndex, style, isScrolling, data } = props;
  const { renderItem, gap, columnCount, dataSource, paddingTop } = data;
  const dataIndex = (0, import_react.useMemo)(() => {
    return columnCount * rowIndex + columnIndex;
  }, [columnCount, rowIndex, columnIndex]);
  const { horizontal, vertical } = (0, import_useGapSize.default)(gap);
  const content = (0, import_react.useMemo)(() => {
    if (dataIndex >= dataSource.length) {
      return null;
    }
    return renderItem(dataSource[dataIndex], dataIndex);
  }, [dataSource, dataIndex, renderItem]);
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        ...style,
        left: ((style == null ? void 0 : style.left) || 0) + columnIndex * horizontal,
        top: ((style == null ? void 0 : style.top) || 0) + paddingTop,
        paddingBottom: vertical
      }
    },
    content
  );
};
var GridComponent = (props) => {
  const {
    dataSource,
    width,
    height,
    renderItem,
    gap,
    itemMaxWidth,
    itemMinWidth,
    rowHeight,
    paddingTop
  } = props;
  const { horizontal, vertical } = (0, import_useGapSize.default)(gap);
  const { columnCount, columnWidth, rowCount } = (0, import_useGenGridProps.default)({
    itemMinWidth,
    itemMaxWidth,
    width,
    dataSource,
    horizontal,
    vertical
  });
  const itemData = (0, import_react.useMemo)(() => {
    return {
      dataSource,
      renderItem,
      columnCount,
      gap,
      paddingTop
    };
  }, [dataSource, columnCount, gap, renderItem, paddingTop]);
  return /* @__PURE__ */ import_react.default.createElement(
    import_react_window.FixedSizeGrid,
    {
      className: (0, import_platform.isMobile)() ? "pisell-lowcode-mobile-gallery" : "",
      columnCount,
      columnWidth,
      height,
      rowCount,
      rowHeight: rowHeight + vertical,
      width,
      itemData
    },
    Cell
  );
};
var VirtualGrid = (props) => {
  const {
    dataSource,
    renderItem,
    gap,
    itemMinWidth,
    itemMaxWidth,
    rowHeight,
    paddingTop = 0
  } = props;
  if (dataSource.length === 0) {
    return /* @__PURE__ */ import_react.default.createElement(import_antd.Empty, { style: { marginTop: 32 }, image: import_antd.Empty.PRESENTED_IMAGE_SIMPLE });
  }
  return /* @__PURE__ */ import_react.default.createElement(import_react_virtualized_auto_sizer.default, null, ({ height, width }) => /* @__PURE__ */ import_react.default.createElement(
    GridComponent,
    {
      paddingTop,
      rowHeight,
      itemMinWidth,
      itemMaxWidth,
      gap,
      width,
      height,
      dataSource,
      renderItem
    }
  ));
};
var VirtualGrid_default = VirtualGrid;
