'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _styleModule = require('./style.module.scss');

var _styleModule2 = _interopRequireDefault(_styleModule);

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var SearchTabs = function (_React$Component) {
  _inherits(SearchTabs, _React$Component);

  function SearchTabs(props) {
    _classCallCheck(this, SearchTabs);

    var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));

    _this.handleTabChange = _this.handleTabChange.bind(_this);
    return _this;
  }

  SearchTabs.prototype.handleTabChange = function handleTabChange(e, tab) {
    e.persist();
    // if not spacebar or enter
    if (e.type === 'keydown' && e.keyCode !== 32 && e.keyCode !== 13) return null;
    return this.props.onTabChange(tab);
  };

  SearchTabs.prototype.render = function render() {
    var _this2 = this;

    var _props = this.props,
        activeTab = _props.activeTab,
        tabNames = _props.tabNames,
        tabFilters = _props.tabFilters;


    var tabs = [{ moduleName: '', label: 'All', icon: _react2.default.createElement('i', { className: 'icon icon-search' }) }, { moduleName: 'docs', label: 'Guides', icon: _react2.default.createElement('i', { className: 'icon icon-documentation-2' }) }, { moduleName: 'reference', label: 'Reference', icon: _react2.default.createElement('i', { className: 'icon icon-reference-2' }) }, { moduleName: 'changelog', label: 'Changelog', icon: _react2.default.createElement('i', { className: 'icon icon-changelog-2' }) }, { moduleName: 'discuss', label: 'Discussions', icon: _react2.default.createElement('i', { className: 'icon icon-discussions-2' }) }, { moduleName: 'custompages', label: 'Pages', icon: _react2.default.createElement('i', { className: 'icon icon-custom-pages' }) }].filter(function (tab) {
      var moduleName = tab.moduleName;

      if (moduleName === '') return true;
      return tabFilters.includes(moduleName);
    });

    return _react2.default.createElement(
      'div',
      { className: _styleModule2.default.SearchTabs },
      _react2.default.createElement(
        'div',
        { className: 'Tabs Tabs-list' },
        tabs.map(function (tab) {
          var activeClass = '';
          if (activeTab === tab.label) activeClass = 'Tabs-listItem_active';
          return _react2.default.createElement(
            'div',
            {
              key: tab.label,
              className: [_styleModule2.default['SearchTabs-Tab'], 'Tabs-listItem', activeClass].join(' '),
              onClick: function onClick(e) {
                return _this2.handleTabChange(e, tab.label);
              },
              onKeyDown: function onKeyDown(e) {
                return _this2.handleTabChange(e, tab.label);
              },
              role: 'button',
              tabIndex: -1
            },
            _react2.default.createElement(
              'span',
              { className: _styleModule2.default['SearchTabs-Tab'] },
              tab.icon,
              tabNames && tab.moduleName && tab.moduleName in tabNames && tabNames[tab.moduleName] || tab.label
            )
          );
        })
      )
    );
  };

  return SearchTabs;
}(_react2.default.Component);

SearchTabs.propTypes = process.env.NODE_ENV !== "production" ? {
  activeTab: _propTypes2.default.string,
  onKeyDown: _propTypes2.default.func,
  onTabChange: _propTypes2.default.func,
  tabFilters: _propTypes2.default.array,
  tabNames: _propTypes2.default.object
} : {};

exports.default = SearchTabs;
module.exports = exports['default'];