"use strict";

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

var _time = require("@opentripplanner/core-utils/lib/time");

var _alertsBody = _interopRequireDefault(require("@opentripplanner/itinerary-body/lib/TransitLegBody/alerts-body"));

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

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

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _user = require("../../../actions/user");

var _tripStatusRenderingStrategies = _interopRequireDefault(require("./trip-status-rendering-strategies"));

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

const StyledFooterButton = (0, _styledComponents.default)(_reactBootstrap.Button)`
  margin-right: 10px;
`;

function FooterButton({
  bsStyle,
  glyphIcon,
  onClick,
  text
}) {
  return /*#__PURE__*/_react.default.createElement(StyledFooterButton, {
    bsStyle: bsStyle,
    onClick: onClick
  }, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Glyphicon, {
    glyph: glyphIcon
  }), " ", text);
}

function MonitoredTripAlerts({
  alerts,
  longDateFormat,
  timeFormat
}) {
  let alertsHeader;

  if (alerts.length === 1) {
    alertsHeader = `${alerts.length} alert!`;
  } else {
    alertsHeader = `${alerts.length} alerts!`;
  }

  return /*#__PURE__*/_react.default.createElement(_reactBootstrap.Panel.Body, null, /*#__PURE__*/_react.default.createElement("h4", null, alertsHeader), /*#__PURE__*/_react.default.createElement(_alertsBody.default, {
    alerts: alerts,
    longDateFormat: longDateFormat,
    timeFormat: timeFormat
  }));
}
/**
 * A functional component that is used to display summary information about a
 * certain monitored trip. It is expected that the renderData for the trip is
 * passed to this component with the necessary data for rendering each portion
 * of this component.
 */


function TripStatus({
  confirmAndDeleteUserMonitoredTrip,
  longDateFormat,
  planNewTripFromMonitoredTrip,
  renderData,
  timeFormat,
  togglePauseTrip,
  toggleSnoozeTrip
}) {
  return /*#__PURE__*/_react.default.createElement(_reactBootstrap.Panel, {
    bsStyle: renderData.panelBsStyle
  }, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Panel.Heading, null, /*#__PURE__*/_react.default.createElement("h3", null, renderData.headingText), /*#__PURE__*/_react.default.createElement("small", null, renderData.lastCheckedText)), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Panel.Body, null, renderData.bodyText), renderData.shouldRenderAlerts && /*#__PURE__*/_react.default.createElement(MonitoredTripAlerts, {
    alerts: renderData.alerts,
    longDateFormat: longDateFormat,
    timeFormat: timeFormat
  }), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Panel.Body, null, renderData.shouldRenderToggleSnoozeTripButton && /*#__PURE__*/_react.default.createElement(FooterButton, {
    glyphIcon: renderData.toggleSnoozeTripButtonGlyphIcon,
    onClick: toggleSnoozeTrip,
    text: renderData.toggleSnoozeTripButtonText
  }), renderData.shouldRenderTogglePauseTripButton && /*#__PURE__*/_react.default.createElement(FooterButton, {
    glyphIcon: renderData.togglePauseTripButtonGlyphIcon,
    onClick: togglePauseTrip,
    text: renderData.togglePauseTripButtonText
  }), renderData.shouldRenderDeleteTripButton && /*#__PURE__*/_react.default.createElement(FooterButton, {
    bsStyle: "error",
    glyphIcon: "trash",
    onClick: confirmAndDeleteUserMonitoredTrip,
    text: "Delete Trip"
  }), renderData.shouldRenderPlanNewTripButton && /*#__PURE__*/_react.default.createElement(FooterButton, {
    glyphIcon: "search",
    onClick: planNewTripFromMonitoredTrip,
    text: "Plan New Trip"
  })));
} // connect to the redux store


const mapStateToProps = (state, ownProps) => {
  const {
    monitoredTrip
  } = ownProps;
  const dateFormat = (0, _time.getDateFormat)(state.otp.config);
  const longDateFormat = (0, _time.getLongDateFormat)(state.otp.config);
  const timeFormat = (0, _time.getTimeFormat)(state.otp.config);
  const renderData = (0, _tripStatusRenderingStrategies.default)({
    dateFormat,
    longDateFormat,
    monitoredTrip,
    onTimeThresholdSeconds: state.otp.config.onTimeThresholdSeconds,
    timeFormat
  });
  return {
    dateFormat,
    longDateFormat,
    renderData,
    timeFormat
  };
};

const mapDispatchToProps = (dispatch, ownProps) => {
  const {
    monitoredTrip
  } = ownProps;
  return {
    confirmAndDeleteUserMonitoredTrip: () => dispatch((0, _user.confirmAndDeleteUserMonitoredTrip)(monitoredTrip.id)),
    planNewTripFromMonitoredTrip: () => dispatch((0, _user.planNewTripFromMonitoredTrip)(monitoredTrip)),
    togglePauseTrip: () => dispatch((0, _user.togglePauseTrip)(monitoredTrip)),
    toggleSnoozeTrip: () => dispatch((0, _user.toggleSnoozeTrip)(monitoredTrip))
  };
};

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

exports.default = _default;

//# sourceMappingURL=trip-status.js