import React__default from 'react';
import { StyledEmptyState } from '../../Combobox.styles.js';
import { classes } from '../../Combobox.tokens.js';
import { VirtualList } from '../VirtualList/VirtualList.js';
import { Item } from './ui/Item/Item.js';
import { ListWrapper, ScrollContainer } from './TreeList.styles.js';
import { isEmpty } from '../../../../utils/isEmpty.js';

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.createElement(VirtualTreeList, {
      items: items,
      listMaxHeight: listMaxHeight,
      onScroll: onScroll,
      beforeList: beforeList,
      afterList: afterList,
      emptyStateDescription: emptyStateDescription
    });
  }
  return /*#__PURE__*/React__default.createElement(ListWrapper, null, /*#__PURE__*/React__default.createElement(ScrollContainer, {
    listMaxHeight: listMaxHeight,
    onScroll: onScroll
  }, beforeList, isEmpty(items) ? /*#__PURE__*/React__default.createElement(StyledEmptyState, {
    className: classes.emptyStateWrapper,
    description: emptyStateDescription || 'Ничего не найдено'
  }) : /*#__PURE__*/React__default.createElement(React__default.Fragment, null, items === null || items === void 0 ? void 0 : items.map(function (item, index) {
    return /*#__PURE__*/React__default.createElement(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.createElement(ListWrapper, null, beforeList, isEmpty(items) ? /*#__PURE__*/React__default.createElement(StyledEmptyState, {
    className: classes.emptyStateWrapper,
    description: emptyStateDescription || 'Ничего не найдено'
  }) : /*#__PURE__*/React__default.createElement(VirtualList, {
    items: items,
    listMaxHeight: listMaxHeight,
    onScroll: onScroll,
    renderItem: function renderItem(item, index) {
      return /*#__PURE__*/React__default.createElement(Item, {
        item: item,
        pathToItem: [index]
      });
    }
  }), afterList);
};

export { TreeList };
