"use strict";

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

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

exports.__esModule = true;
exports.Column = exports.ItemType = 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 _ColumnItem = require("./ColumnItem");

var ItemType = _propTypes.default.shape({
  id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
  name: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
  parentId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
  raw: _propTypes.default.any
});

exports.ItemType = ItemType;

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

  function Column() {
    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), "renderItem", function (_ref, index) {
      var id = _ref.id,
          name = _ref.name;
      var _this$props = _this.props,
          selectedId = _this$props.selectedId,
          isActive = _this$props.isActive,
          countChildren = _this$props.countChildren,
          onSelect = _this$props.onSelect;
      return _react.default.createElement(_ColumnItem.ColumnItem, {
        key: id,
        id: id,
        name: name,
        isSelected: id === selectedId,
        isPrimary: id === selectedId && isActive,
        numChildren: countChildren(id),
        onSelect: onSelect,
        index: index
      });
    });
    return _this;
  }

  var _proto = Column.prototype;

  _proto.render = function render() {
    var _this$props2 = this.props,
        items = _this$props2.items,
        index = _this$props2.index;
    return _react.default.createElement("div", {
      className: "rc-column-tree-view-col",
      "data-test-automation-id": "columnTreeViewColumn" + index
    }, _react.default.createElement("div", {
      className: "rc-column-tree-view-col-content"
    }, items.map(this.renderItem)));
  };

  return Column;
}(_react.Component);

exports.Column = Column;
(0, _defineProperty2.default)(Column, "propTypes", {
  isActive: _propTypes.default.bool,
  selectedId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
  items: _propTypes.default.arrayOf(ItemType),
  onSelect: _propTypes.default.func,
  countChildren: _propTypes.default.func,
  index: _propTypes.default.number.isRequired
});
(0, _defineProperty2.default)(Column, "defaultProps", {
  isActive: false,
  selectedId: null,
  items: [],
  onSelect: function onSelect(id) {},
  countChildren: function countChildren(id) {
    return 0;
  }
});