var _excluded = ["children"],
  _excluded2 = ["children", "index"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { forwardRef, useMemo, memo } from 'react';
import classNames from 'classnames';
// 将默认组件移到组件外部，避免重复创建
var DefaultListComponent = /*#__PURE__*/memo(function (_ref) {
  var children = _ref.children,
    listProps = _objectWithoutProperties(_ref, _excluded);
  return /*#__PURE__*/React.createElement("div", _extends({
    className: "product-list-wrapper"
  }, listProps), children);
});
var DefaultItemComponent = /*#__PURE__*/memo(function (_ref2) {
  var children = _ref2.children,
    index = _ref2.index,
    itemProps = _objectWithoutProperties(_ref2, _excluded2);
  return /*#__PURE__*/React.createElement("div", _extends({}, itemProps, {
    "data-index": index,
    "data-item-index": index
  }), children);
});
var ProductList = /*#__PURE__*/forwardRef(function (props, ref) {
  var className = props.className,
    data = props.data,
    context = props.context,
    components = props.components,
    itemContent = props.itemContent;

  // 使用 useMemo 缓存组件选择
  var ListComponent = useMemo(function () {
    return (components === null || components === void 0 ? void 0 : components.List) || DefaultListComponent;
  }, [components === null || components === void 0 ? void 0 : components.List]);
  var ItemComponent = useMemo(function () {
    return (components === null || components === void 0 ? void 0 : components.Item) || DefaultItemComponent;
  }, [components === null || components === void 0 ? void 0 : components.Item]);
  var itemContentRenderer = useMemo(function () {
    if (itemContent) {
      return function (item, index) {
        return itemContent(index, item, context);
      };
    }
    return function (item, index) {
      return /*#__PURE__*/React.createElement("div", null, index);
    };
  }, [itemContent, context]);
  var renderedItems = useMemo(function () {
    return data === null || data === void 0 ? void 0 : data.map(function (item, index) {
      var content = itemContentRenderer(item, index);
      return /*#__PURE__*/React.createElement(ItemComponent, {
        key: "".concat(item.id || index, "-").concat(index),
        item: item,
        index: index,
        "data-index": index,
        "data-item-index": index,
        context: context
      }, content);
    });
  }, [data, ItemComponent, itemContentRenderer]);
  return /*#__PURE__*/React.createElement("div", {
    className: classNames(className)
  }, /*#__PURE__*/React.createElement(ListComponent, {
    ref: ref,
    context: context
  }, renderedItems));
});
export default ProductList;

// 导出网格组件工厂函数，方便外部使用
export { createGridComponents, createTwoColumnGrid, createCustomGrid, GRID_LAYOUTS } from "./gridComponents";