"use strict";

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

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

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

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

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

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

var _mobxReactLite = require("mobx-react-lite");

var _sortBy = _interopRequireDefault(require("lodash/sortBy"));

var _reactBeautifulDnd = require("react-beautiful-dnd");

var _TreeNode = _interopRequireDefault(require("../tree/TreeNode"));

var _SubGroup = _interopRequireDefault(require("./SubGroup"));

var _TableContext = _interopRequireDefault(require("../../TableContext"));

var _excluded = ["treeNodeRenderer", "treeNodeSuffix", "records", "onDragEnd"];

var SubGroups = function SubGroups(props) {
  var treeNodeRenderer = props.treeNodeRenderer,
      treeNodeSuffix = props.treeNodeSuffix,
      records = props.records,
      onDragEnd = props.onDragEnd,
      rest = (0, _objectWithoutProperties2["default"])(props, _excluded);

  var _useContext = (0, _react.useContext)(_TableContext["default"]),
      columnDraggable = _useContext.tableStore.columnDraggable;

  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, (0, _sortBy["default"])(records, [function (r) {
    return r.get('sort');
  }]).map(function (record, index, list) {
    var children = record.children ? /*#__PURE__*/_react["default"].createElement(_SubGroup["default"], (0, _extends2["default"])({
      key: record.key,
      record: record,
      childrenRecords: record.children,
      onDragEnd: onDragEnd,
      treeNodeRenderer: treeNodeRenderer,
      treeNodeSuffix: treeNodeSuffix,
      index: index,
      records: list
    }, rest)) : /*#__PURE__*/_react["default"].createElement(_TreeNode["default"], (0, _extends2["default"])({
      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["default"].createElement(_reactBeautifulDnd.Draggable, {
      key: record.key,
      draggableId: String(record.key),
      index: index
    }, function (provided, snapshot) {
      return /*#__PURE__*/(0, _react.cloneElement)(children, {
        provided: provided,
        snapshot: snapshot
      });
    }) : children;
  }));
};

SubGroups.displayName = 'SubGroups';

var _default = (0, _mobxReactLite.observer)(SubGroups);

exports["default"] = _default;
//# sourceMappingURL=SubGroups.js.map
