'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var Combobox_styles = require('../../Combobox.styles.js');
var Combobox_tokens = require('../../Combobox.tokens.js');
var VirtualList = require('../VirtualList/VirtualList.js');
var Item = require('./ui/Item/Item.js');
var TreeList_styles = require('./TreeList.styles.js');
var isEmpty = require('../../../../utils/isEmpty.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var TreeList = function TreeList(_ref) {
  var items = _ref.items,
    listMaxHeight = _ref.listMaxHeight,
    onScroll = _ref.onScroll,
    virtual = _ref.virtual,
    beforeList = _ref.beforeList,
    afterList = _ref.afterList,
    emptyStateDescription = _ref.emptyStateDescription;
  if (virtual) {
    return /*#__PURE__*/React__default.default.createElement(VirtualTreeList, {
      items: items,
      listMaxHeight: listMaxHeight,
      onScroll: onScroll,
      beforeList: beforeList,
      afterList: afterList,
      emptyStateDescription: emptyStateDescription
    });
  }
  return /*#__PURE__*/React__default.default.createElement(TreeList_styles.ListWrapper, null, /*#__PURE__*/React__default.default.createElement(TreeList_styles.ScrollContainer, {
    listMaxHeight: listMaxHeight,
    onScroll: onScroll
  }, beforeList, isEmpty.isEmpty(items) ? /*#__PURE__*/React__default.default.createElement(Combobox_styles.StyledEmptyState, {
    className: Combobox_tokens.classes.emptyStateWrapper,
    description: emptyStateDescription || 'Ничего не найдено'
  }) : /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, items === null || items === void 0 ? void 0 : items.map(function (item, index) {
    return /*#__PURE__*/React__default.default.createElement(Item.Item, {
      key: index,
      item: item,
      pathToItem: [index]
    });
  })), afterList));
};
var VirtualTreeList = function VirtualTreeList(_ref2) {
  var _ref2$items = _ref2.items,
    items = _ref2$items === void 0 ? [] : _ref2$items,
    listMaxHeight = _ref2.listMaxHeight,
    onScroll = _ref2.onScroll,
    beforeList = _ref2.beforeList,
    afterList = _ref2.afterList,
    emptyStateDescription = _ref2.emptyStateDescription;
  return /*#__PURE__*/React__default.default.createElement(TreeList_styles.ListWrapper, null, beforeList, isEmpty.isEmpty(items) ? /*#__PURE__*/React__default.default.createElement(Combobox_styles.StyledEmptyState, {
    className: Combobox_tokens.classes.emptyStateWrapper,
    description: emptyStateDescription || 'Ничего не найдено'
  }) : /*#__PURE__*/React__default.default.createElement(VirtualList.VirtualList, {
    items: items,
    listMaxHeight: listMaxHeight,
    onScroll: onScroll,
    renderItem: function renderItem(item, index) {
      return /*#__PURE__*/React__default.default.createElement(Item.Item, {
        item: item,
        pathToItem: [index]
      });
    }
  }), afterList);
};

exports.TreeList = TreeList;
