"use strict";

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

require("core-js/modules/es6.object.assign");

var _react = _interopRequireDefault(require("react"));

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

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }

/**
 * Tab is supplemental, clickable component used to help navigate content
 * @param props
 * @returns {XML}
 * @constructor
 */
var Tab =
/*#__PURE__*/
function (_React$PureComponent) {
  _inheritsLoose(Tab, _React$PureComponent);

  function Tab() {
    return _React$PureComponent.apply(this, arguments) || this;
  }

  var _proto = Tab.prototype;

  _proto.componentDidUpdate = function componentDidUpdate() {
    this.props.focus && this.tabLink.focus();
  };

  _proto.render = function render() {
    var _this = this;

    var _this$props = this.props,
        heading = _this$props.heading,
        active = _this$props.active,
        onPress = _this$props.onPress,
        onKeyDown = _this$props.onKeyDown,
        role = _this$props.role,
        focus = _this$props.focus,
        className = _this$props.className,
        disabled = _this$props.disabled;
    /* Due to Collab UI must keep anchor element instead of button
     eventhough accessibility would like the anchor element to be switched
     to a button. */

    /* eslint-disable */

    return _react.default.createElement("li", _extends({
      className: 'cui-tab__item' + ("" + (className && " " + className || '')) + ("" + (active ? ' active' : '')) + ("" + (disabled ? ' disabled' : ''))
    }, !disabled ? {
      tabIndex: '-1'
    } : {}), _react.default.createElement("a", {
      ref: function ref(_ref) {
        return _this.tabLink = _ref;
      },
      role: role,
      href: "javascript:void(0)",
      onKeyDown: onKeyDown,
      onClick: onPress,
      tabIndex: focus ? 0 : -1,
      "aria-current": active
    }, heading));
  };

  return Tab;
}(_react.default.PureComponent);
/* eslint-enable */


Tab.displayName = 'Tab';
Tab.propTypes = {
  /**
   * required function for onClick events
   */
  onPress: _propTypes.default.func,

  /**
   * required function for keyPress events
   */
  onKeyDown: _propTypes.default.func,

  /**
   * required heading prop type
   */
  heading: _propTypes.default.string.isRequired,

  /**
   * optional active prop type
   */
  active: _propTypes.default.bool,

  /** focus prop for whether focus should change */
  focus: _propTypes.default.bool,

  /**
   * optional role prop type
   */
  role: _propTypes.default.string,

  /**
   * optional className prop
   */
  className: _propTypes.default.string,

  /**
   * optional disabled prop
   */
  disabled: _propTypes.default.bool
};
Tab.defaultProps = {
  active: false,
  myKey: 0,
  onPress: null,
  onKeyPress: null,
  role: 'tab',
  focus: false,
  className: '',
  disabled: false
};
var _default = Tab;
exports.default = _default;