"use strict";

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

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

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

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

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

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

var planActions = _interopRequireWildcard(require("../../actions/plan"));

var _state = require("../../util/state");

var _styled = require("./styled");

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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function PlanFirstLastButtons(props) {
  const {
    enabled,
    itineraries,
    planFirst,
    planLast,
    planNext,
    planPrevious
  } = props;

  if (!enabled || itineraries.length === 0) {
    return null;
  }

  return /*#__PURE__*/_react.default.createElement(_styled.FlexButtonGroup, null, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
    bsSize: "small",
    onClick: planFirst
  }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
    id: "components.PlanFirstLastButtons.first"
  })), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
    bsSize: "small",
    onClick: planPrevious
  }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
    id: "components.PlanFirstLastButtons.previous"
  })), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
    bsSize: "small",
    onClick: planNext
  }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
    id: "components.PlanFirstLastButtons.next"
  })), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
    bsSize: "small",
    onClick: planLast
  }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
    id: "components.PlanFirstLastButtons.last"
  })));
}

const mapStateToProps = (state, ownProps) => {
  var _state$otp$config$iti;

  const itineraries = (0, _state.getActiveItineraries)(state);
  return {
    enabled: (_state$otp$config$iti = state.otp.config.itinerary) === null || _state$otp$config$iti === void 0 ? void 0 : _state$otp$config$iti.showPlanFirstLastButtons,
    itineraries
  };
};

const mapDispatchToProps = {
  planFirst: planActions.planFirst,
  planLast: planActions.planLast,
  planNext: planActions.planNext,
  planPrevious: planActions.planPrevious
};

var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(PlanFirstLastButtons);

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

//# sourceMappingURL=plan-first-last-buttons.js