"use strict";

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

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

exports.__esModule = true;
exports.ColumnTreeView = void 0;

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

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

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

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _classnames = _interopRequireDefault(require("classnames"));

var _Column = require("./Column");

var ColumnTreeView =
/*#__PURE__*/
function (_Component) {
  (0, _inheritsLoose2.default)(ColumnTreeView, _Component);

  function ColumnTreeView() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _Component.call.apply(_Component, [this].concat(args)) || this;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderColumn", function (_ref, index) {
      var parentId = _ref.parentId,
          isActive = _ref.isActive,
          selectedId = _ref.selectedId,
          items = _ref.items;
      var _this$props = _this.props,
          onSelect = _this$props.onSelect,
          countChildren = _this$props.countChildren;
      return _react.default.createElement(_Column.Column, {
        key: parentId,
        isActive: isActive,
        selectedId: selectedId,
        items: items,
        onSelect: onSelect,
        countChildren: countChildren,
        index: index
      });
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderChildren", function () {
      var children = _this.props.children;
      var wrappedChildren = null;

      if (children) {
        wrappedChildren = _react.default.createElement("div", {
          className: "rc-column-tree-view-content"
        }, children);
      }

      return wrappedChildren;
    });
    return _this;
  }

  var _proto = ColumnTreeView.prototype;

  _proto.render = function render() {
    var _this$props2 = this.props,
        columns = _this$props2.columns,
        testAutomationId = _this$props2.testAutomationId,
        fixedHeight = _this$props2.fixedHeight;
    var classNames = (0, _classnames.default)('rc-column-tree-view', {
      'rc-column-tree-view-fixed-height': fixedHeight
    });
    return _react.default.createElement("div", {
      className: classNames,
      "data-test-automation-id": testAutomationId
    }, columns.map(this.renderColumn), this.renderChildren());
  };

  return ColumnTreeView;
}(_react.Component);

exports.ColumnTreeView = ColumnTreeView;
(0, _defineProperty2.default)(ColumnTreeView, "propTypes", {
  children: _propTypes.default.node,
  columns: _propTypes.default.arrayOf(_propTypes.default.shape({
    parentId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
    isActive: _propTypes.default.bool,
    selectedId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
    items: _propTypes.default.arrayOf(_Column.ItemType)
  })),
  onSelect: _propTypes.default.func,
  countChildren: _propTypes.default.func,
  testAutomationId: _propTypes.default.string,
  fixedHeight: _propTypes.default.bool
});
(0, _defineProperty2.default)(ColumnTreeView, "defaultProps", {
  children: null,
  columns: [],
  onSelect: function onSelect(id) {},
  countChildren: function countChildren(id) {
    return 0;
  },
  testAutomationId: 'columnTreeView',
  fixedHeight: false
});