import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { Icon } from '../Icon';
export var ColumnItem =
/*#__PURE__*/
function (_PureComponent) {
  _inheritsLoose(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;

    _defineProperty(_assertThisInitialized(_this), "getClassNames", function () {
      var _this$props = _this.props,
          isSelected = _this$props.isSelected,
          isPrimary = _this$props.isPrimary;
      return classnames('rc-column-tree-view-item', {
        'rc-column-tree-view-item-selected': isSelected,
        'rc-column-tree-view-item-selected-active': isSelected && isPrimary
      });
    });

    _defineProperty(_assertThisInitialized(_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.createElement("button", {
      title: name,
      onClick: this.handleSelect,
      className: this.getClassNames(),
      "data-test-automation-id": "columnTreeViewItem" + index
    }, React.createElement("div", {
      className: "rc-column-tree-view-item-name"
    }, name, childrenCount), React.createElement(Icon, {
      name: "chevron-right-small"
    }));
  };

  return ColumnItem;
}(PureComponent);

_defineProperty(ColumnItem, "propTypes", {
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
  name: PropTypes.string.isRequired,
  isSelected: PropTypes.bool,
  isPrimary: PropTypes.bool,
  numChildren: PropTypes.number,
  onSelect: PropTypes.func,
  index: PropTypes.number.isRequired
});

_defineProperty(ColumnItem, "defaultProps", {
  isSelected: false,
  isPrimary: false,
  numChildren: 0,
  onSelect: function onSelect(id) {}
});