'use strict';

import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import { LinkContainer } from 'react-router-bootstrap';
import NavItem from 'react-bootstrap/lib/NavItem';
export var TabItem =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(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;

    _defineProperty(_assertThisInitialized(_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.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 = _objectWithoutPropertiesLoose(_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.createElement(LinkContainer, props, React.createElement(NavItem, null, children));
    }

    return React.createElement(NavItem, props, children);
  };

  _createClass(TabItem, null, [{
    key: "contextTypes",
    get: function get() {
      return {
        router: PropTypes.object,
        isStyledAsTab: PropTypes.func
      };
    }
  }]);

  return TabItem;
}(React.Component);

_defineProperty(TabItem, "propTypes", {
  children: PropTypes.node.isRequired,
  to: PropTypes.string,
  testAutomationId: PropTypes.string,
  active: PropTypes.bool,
  onClick: PropTypes.func,
  eventKey: PropTypes.any,
  activeKey: PropTypes.any
});

_defineProperty(TabItem, "defaultProps", {
  testAutomationId: null,
  to: null,
  active: null,
  onClick: null,
  eventKey: null,
  activeKey: null
});