"use strict";

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

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

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

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

  function ColumnItem() {
    var _this;

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

    _this = _PureComponent.call.apply(_PureComponent, [this].concat(args)) || this;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getClassNames", function () {
      var _this$props = _this.props,
          isSelected = _this$props.isSelected,
          isPrimary = _this$props.isPrimary;
      return (0, _classnames.default)('rc-column-tree-view-item', {
        'rc-column-tree-view-item-selected': isSelected,
        'rc-column-tree-view-item-selected-active': isSelected && isPrimary
      });
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleSelect", function () {
      var _this$props2 = _this.props,
          id = _this$props2.id,
          onSelect = _this$props2.onSelect;
      onSelect(id);
    });
    return _this;
  }

  var _proto = ColumnItem.prototype;

  _proto.render = function render() {
    var _this$props3 = this.props,
        name = _this$props3.name,
        numChildren = _this$props3.numChildren,
        index = _this$props3.index;
    var childrenCount = numChildren > 0 ? " (" + numChildren + ")" : null;
    return _react.default.createElement("button", {
      title: name,
      onClick: this.handleSelect,
      className: this.getClassNames(),
      "data-test-automation-id": "columnTreeViewItem" + index
    }, _react.default.createElement("div", {
      className: "rc-column-tree-view-item-name"
    }, name, childrenCount), _react.default.createElement(_Icon.Icon, {
      name: "chevron-right-small"
    }));
  };

  return ColumnItem;
}(_react.PureComponent);

exports.ColumnItem = ColumnItem;
(0, _defineProperty2.default)(ColumnItem, "propTypes", {
  id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
  name: _propTypes.default.string.isRequired,
  isSelected: _propTypes.default.bool,
  isPrimary: _propTypes.default.bool,
  numChildren: _propTypes.default.number,
  onSelect: _propTypes.default.func,
  index: _propTypes.default.number.isRequired
});
(0, _defineProperty2.default)(ColumnItem, "defaultProps", {
  isSelected: false,
  isPrimary: false,
  numChildren: 0,
  onSelect: function onSelect(id) {}
});