"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.ListContext = void 0;

var _react = _interopRequireDefault(require("react"));

var _context = require("../config-provider/context");

var _listItem = _interopRequireDefault(require("./list-item"));

var _index = _interopRequireDefault(require("../pagination/index"));

// import useMemo from '@/components/rc-util/hooks/useMemo';
var ListContext = /*#__PURE__*/_react.default.createContext({});

exports.ListContext = ListContext;

var ListHoc = function ListHoc(props, ref) {
  var dataSource = props.dataSource,
      renderItem = props.renderItem,
      split = props.split,
      direction = props.direction,
      pagination = props.pagination,
      loadMore = props.loadMore,
      itemLayout = props.itemLayout,
      size = props.size,
      locale = props.locale;

  var _React$useContext = _react.default.useContext(_context.ConfigContext),
      getPrefixClassName = _React$useContext.getPrefixClassName;

  var listPrefix = getPrefixClassName('list');

  var renderEmptyFunc = function renderEmptyFunc(prefixCls) {
    return /*#__PURE__*/_react.default.createElement("div", {
      className: "".concat(prefixCls, "-empty")
    }, locale);
  };

  return /*#__PURE__*/_react.default.createElement(ListContext.Provider, {
    value: {
      itemLayout: itemLayout,
      size: size,
      direction: direction,
      split: split
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    ref: ref,
    className: "".concat(listPrefix, "-container")
  }, dataSource.length > 0 ? /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(listPrefix, "-list ").concat(direction)
  }, dataSource === null || dataSource === void 0 ? void 0 : dataSource.map(function (item) {
    return renderItem === null || renderItem === void 0 ? void 0 : renderItem(item);
  })) : renderEmptyFunc(listPrefix), pagination && /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(listPrefix, "-pagination")
  }, /*#__PURE__*/_react.default.createElement(_index.default, Object.assign({}, pagination))), !pagination && loadMore));
};

var List = /*#__PURE__*/_react.default.forwardRef(ListHoc);

List.Item = _listItem.default;
List.defaultProps = {
  dataSource: [],
  itemLayout: 'horizontal',
  size: 'default',
  split: true,
  direction: 'vertical'
};
var _default = List;
exports.default = _default;