"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

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

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

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

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

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

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

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

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

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }

// Style
var classes = {};
/* istanbul ignore next */

if (typeof window !== 'undefined') classes = require("./style.module.scss");

var SearchTabs = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(SearchTabs, _React$Component);

  var _super = _createSuper(SearchTabs);

  function SearchTabs(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, SearchTabs);
    _this = _super.call(this, props);
    _this.handleTabChange = _this.handleTabChange.bind((0, _assertThisInitialized2["default"])(_this));
    return _this;
  }

  (0, _createClass2["default"])(SearchTabs, [{
    key: "handleTabChange",
    value: 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);
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props = this.props,
          activeTab = _this$props.activeTab,
          tabNames = _this$props.tabNames,
          tabFilters = _this$props.tabFilters;
      var tabs = [{
        moduleName: '',
        label: 'All',
        icon: /*#__PURE__*/_react["default"].createElement("i", {
          className: "icon icon-search"
        })
      }, {
        moduleName: 'docs',
        label: 'Guides',
        icon: /*#__PURE__*/_react["default"].createElement("i", {
          className: "icon icon-documentation-2"
        })
      }, {
        moduleName: 'reference',
        label: 'Reference',
        icon: /*#__PURE__*/_react["default"].createElement("i", {
          className: "icon icon-reference-2"
        })
      }, {
        moduleName: 'changelog',
        label: 'Changelog',
        icon: /*#__PURE__*/_react["default"].createElement("i", {
          className: "icon icon-changelog-2"
        })
      }, {
        moduleName: 'discuss',
        label: 'Discussions',
        icon: /*#__PURE__*/_react["default"].createElement("i", {
          className: "icon icon-discussions-2"
        })
      }, {
        moduleName: 'custompages',
        label: 'Pages',
        icon: /*#__PURE__*/_react["default"].createElement("i", {
          className: "icon icon-custom-pages"
        })
      }].filter(function (tab) {
        var moduleName = tab.moduleName;
        if (moduleName === '') return true;
        return tabFilters.includes(moduleName);
      });
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: classes.SearchTabs
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: "Tabs Tabs-list"
      }, tabs.map(function (tab) {
        var activeClass = '';
        if (activeTab === tab.label) activeClass = 'Tabs-listItem_active';
        return /*#__PURE__*/_react["default"].createElement("div", {
          key: tab.label,
          className: [classes['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
        }, /*#__PURE__*/_react["default"].createElement("span", {
          className: classes['SearchTabs-Tab']
        }, tab.icon, tabNames && tab.moduleName && tab.moduleName in tabNames && tabNames[tab.moduleName] || tab.label));
      })));
    }
  }]);
  return SearchTabs;
}(_react["default"].Component);

SearchTabs.propTypes = {
  activeTab: _propTypes["default"].string,
  onKeyDown: _propTypes["default"].func,
  onTabChange: _propTypes["default"].func,
  tabFilters: _propTypes["default"].array,
  tabNames: _propTypes["default"].object
};
var _default = SearchTabs;
exports["default"] = _default;