'use strict';

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

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

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

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

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 = _interopRequireDefault(require("react"));

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

var _reactDom = _interopRequireDefault(require("react-dom"));

var _reactRouterBootstrap = require("react-router-bootstrap");

var _NavItem = _interopRequireDefault(require("react-bootstrap/lib/NavItem"));

var TabItem =
/*#__PURE__*/
function (_React$Component) {
  (0, _inheritsLoose2.default)(TabItem, _React$Component);

  function TabItem() {
    var _this;

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

    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleClick", function (event) {
      if (_this.props.onClick) {
        _this.props.onClick(event);
      }
    });
    return _this;
  }

  var _proto = TabItem.prototype;

  _proto.componentDidMount = function componentDidMount() {
    var testAutomationId = this.props.testAutomationId;

    var node = _reactDom.default.findDOMNode(this);

    if (node) {
      node.setAttribute('data-test-automation-id', testAutomationId);
    }
  };

  _proto.getTabProps = function getTabProps() {
    var _this$props = this.props,
        testAutomationId = _this$props.testAutomationId,
        props = (0, _objectWithoutPropertiesLoose2.default)(_this$props, ["testAutomationId"]);
    props = Object.assign({
      role: 'tab'
    }, props, {
      onClick: this.handleClick,
      tabIndex: -1
    });
    return props;
  };

  _proto.render = function render() {
    var _this$props2 = this.props,
        to = _this$props2.to,
        children = _this$props2.children;
    var props = this.getTabProps();

    if (to) {
      return _react.default.createElement(_reactRouterBootstrap.LinkContainer, props, _react.default.createElement(_NavItem.default, null, children));
    }

    return _react.default.createElement(_NavItem.default, props, children);
  };

  (0, _createClass2.default)(TabItem, null, [{
    key: "contextTypes",
    get: function get() {
      return {
        router: _propTypes.default.object,
        isStyledAsTab: _propTypes.default.func
      };
    }
  }]);
  return TabItem;
}(_react.default.Component);

exports.TabItem = TabItem;
(0, _defineProperty2.default)(TabItem, "propTypes", {
  children: _propTypes.default.node.isRequired,
  to: _propTypes.default.string,
  testAutomationId: _propTypes.default.string,
  active: _propTypes.default.bool,
  onClick: _propTypes.default.func,
  eventKey: _propTypes.default.any,
  activeKey: _propTypes.default.any
});
(0, _defineProperty2.default)(TabItem, "defaultProps", {
  testAutomationId: null,
  to: null,
  active: null,
  onClick: null,
  eventKey: null,
  activeKey: null
});