import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import React from 'react';
import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect';
import Overlay from '../../../components/Overlay';
import { routeProp } from '../../../utils/propTypes';
import * as routerSelectors from '../../Router/selectors';
import * as actions from '../actions';
import * as selectors from '../selectors';
import Branding from './Branding';
import LocationBar from './LocationBar';
import MobileControls from './MobileControls';
import Navigation from './Navigation';
import Search from './Search';
import SettingsBar from './SettingsBar';
import UtilityHeader from './UtilityHeader';

var Header =
/*#__PURE__*/
function (_React$PureComponent) {
  _inherits(Header, _React$PureComponent);

  function Header() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, Header);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Header)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.toggleMobileOpen = function () {
      var _this$props = _this.props,
          isMobileOpen = _this$props.isMobileOpen,
          updateDisplay = _this$props.updateDisplay;
      updateDisplay({
        isMobileOpen: !isMobileOpen
      });
    };

    _this.toggleSettingsOpen = function () {
      var _this$props2 = _this.props,
          isSettingsOpen = _this$props2.isSettingsOpen,
          updateDisplay = _this$props2.updateDisplay;
      updateDisplay({
        isSettingsOpen: !isSettingsOpen
      });
    };

    return _this;
  }

  _createClass(Header, [{
    key: "render",
    value: function render() {
      var _this$props3 = this.props,
          isMobileOpen = _this$props3.isMobileOpen,
          isSettingsOpen = _this$props3.isSettingsOpen,
          routes = _this$props3.routes,
          contactLink = _this$props3.contactLink,
          brandingLogo = _this$props3.brandingLogo;
      var filteredRoutes = routes.filter(function (x) {
        return !x.hidden;
      });
      return React.createElement("header", {
        role: "banner",
        id: "header",
        className: "global-header fixed"
      }, React.createElement("div", {
        id: "skip-to-content"
      }, React.createElement("a", {
        href: "#main-content"
      }, "Skip to Main Content")), React.createElement(LocationBar, null), React.createElement(UtilityHeader, {
        toggleSettingsOpen: this.toggleSettingsOpen,
        contactLink: contactLink
      }), React.createElement(SettingsBar, {
        isSettingsOpen: isSettingsOpen,
        toggleSettingsOpen: this.toggleSettingsOpen
      }), React.createElement(Branding, {
        src: brandingLogo
      }), React.createElement(MobileControls, {
        toggleMobileOpen: this.toggleMobileOpen,
        routes: filteredRoutes
      }), React.createElement("div", {
        className: "navigation-search"
      }, React.createElement(Navigation, {
        isMobileOpen: isMobileOpen,
        toggleMobileOpen: this.toggleMobileOpen,
        routes: filteredRoutes
      }), React.createElement("div", {
        id: "head-search",
        className: "search-container"
      }, React.createElement(Search, null))), React.createElement(Overlay, {
        show: isMobileOpen,
        onClick: this.toggleMobileOpen,
        isMobile: true
      }), React.createElement("div", {
        className: "header-decoration"
      }));
    }
  }]);

  return Header;
}(React.PureComponent);

export var mapStateToProps = createStructuredSelector({
  isMobileOpen: selectors.getIsMobileOpen(),
  isSettingsOpen: selectors.getIsSettingsOpen(),
  routes: routerSelectors.getRoutes(),
  contactLink: routerSelectors.getContactLink()
});
export var mapDispatchToProps = function mapDispatchToProps(dispatch) {
  return {
    updateDisplay: function updateDisplay(props) {
      return dispatch(actions.updateDisplay(props));
    }
  };
};
var withRedux = connect(mapStateToProps, mapDispatchToProps);
export default withRedux(Header);