import "core-js/modules/es6.object.assign";

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; }

import React from 'react';
import PropTypes from 'prop-types';
/**
 * 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.createElement("li", _extends({
      className: 'cui-tab__item' + ("" + (className && " " + className || '')) + ("" + (active ? ' active' : '')) + ("" + (disabled ? ' disabled' : ''))
    }, !disabled ? {
      tabIndex: '-1'
    } : {}), React.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.PureComponent);
/* eslint-enable */


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

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

  /**
   * required heading prop type
   */
  heading: PropTypes.string.isRequired,

  /**
   * optional active prop type
   */
  active: PropTypes.bool,

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

  /**
   * optional role prop type
   */
  role: PropTypes.string,

  /**
   * optional className prop
   */
  className: PropTypes.string,

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