import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["treeNodeRenderer", "treeNodeSuffix", "records", "onDragEnd"];
import React, { cloneElement, useContext } from 'react';
import { observer } from 'mobx-react-lite';
import sortBy from 'lodash/sortBy';
import { Draggable } from 'react-beautiful-dnd';
import TreeNode from '../tree/TreeNode';
import SubGroup from './SubGroup';
import TableContext from '../../TableContext';

var SubGroups = function SubGroups(props) {
  var treeNodeRenderer = props.treeNodeRenderer,
      treeNodeSuffix = props.treeNodeSuffix,
      records = props.records,
      onDragEnd = props.onDragEnd,
      rest = _objectWithoutProperties(props, _excluded);

  var _useContext = useContext(TableContext),
      columnDraggable = _useContext.tableStore.columnDraggable;

  return /*#__PURE__*/React.createElement(React.Fragment, null, sortBy(records, [function (r) {
    return r.get('sort');
  }]).map(function (record, index, list) {
    var children = record.children ? /*#__PURE__*/React.createElement(SubGroup, _extends({
      key: record.key,
      record: record,
      childrenRecords: record.children,
      onDragEnd: onDragEnd,
      treeNodeRenderer: treeNodeRenderer,
      treeNodeSuffix: treeNodeSuffix,
      index: index,
      records: list
    }, rest)) : /*#__PURE__*/React.createElement(TreeNode, _extends({
      key: record.key,
      record: record,
      isLeaf: true,
      renderer: treeNodeRenderer,
      suffix: treeNodeSuffix,
      index: index,
      records: list
    }, rest));
    return columnDraggable && record.get('draggable') !== false && (!record.parent || list.length > 1) ? /*#__PURE__*/React.createElement(Draggable, {
      key: record.key,
      draggableId: String(record.key),
      index: index
    }, function (provided, snapshot) {
      return /*#__PURE__*/cloneElement(children, {
        provided: provided,
        snapshot: snapshot
      });
    }) : children;
  }));
};

SubGroups.displayName = 'SubGroups';
export default observer(SubGroups);
//# sourceMappingURL=SubGroups.js.map
