"use strict";

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

require("core-js/modules/web.dom.iterable");

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

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

var _reactBootstrap = require("react-bootstrap");

var _reactRouter = require("react-router");

var _reactRedux = require("react-redux");

var _reactIntl = require("react-intl");

var _ui = require("../../actions/ui");

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/**
 * This component is a switcher between
 * the main views of the application.
 */
class ViewSwitcher extends _react.Component {
  constructor(...args) {
    super(...args);

    _defineProperty(this, "_showRouteViewer", () => {
      this.props.setMainPanelContent(_ui.MainPanelContent.ROUTE_VIEWER);
    });

    _defineProperty(this, "_showTripPlanner", () => {
      this.props.setMainPanelContent(null);
    });
  }

  render() {
    const {
      activePanel,
      sticky
    } = this.props;
    return /*#__PURE__*/_react.default.createElement("div", {
      "aria-label": "Switcher",
      className: "view-switcher",
      role: "navigation",
      style: sticky && {
        height: '100%',
        left: 0,
        position: 'absolute',
        width: '100%'
      }
    }, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
      bsStyle: "link",
      className: activePanel === null && 'active',
      onClick: this._showTripPlanner
    }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: "components.BatchRoutingPanel.shortTitle"
    })), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
      bsStyle: "link",
      className: activePanel === _ui.MainPanelContent.ROUTE_VIEWER && 'active',
      onClick: this._showRouteViewer
    }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: "components.RouteViewer.shortTitle"
    })));
  }

} // connect to the redux store


_defineProperty(ViewSwitcher, "propTypes", {
  activePanel: _propTypes.default.number,
  setMainPanelContent: _propTypes.default.func,
  sticky: _propTypes.default.bool
});

const mapStateToProps = (state, ownProps) => {
  const {
    mainPanelContent
  } = state.otp.ui; // Reverse the ID to string mapping

  let activePanel = Object.entries(_ui.MainPanelContent).find(keyValuePair => keyValuePair[1] === mainPanelContent); // activePanel is array of form [string, ID]
  // The trip planner has id null

  activePanel = activePanel && activePanel[1] || null;
  return {
    activePanel
  };
};

const mapDispatchToProps = {
  setMainPanelContent: _ui.setMainPanelContent
};

var _default = (0, _reactRouter.withRouter)((0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(ViewSwitcher));

exports.default = _default;
module.exports = exports.default;

//# sourceMappingURL=view-switcher.js