"use strict";

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

var _activeTripRenderer = _interopRequireDefault(require("./active-trip-renderer"));

var _inactiveRenderer = _interopRequireDefault(require("./inactive-renderer"));

var _nextTripNotPossibleRenderer = _interopRequireDefault(require("./next-trip-not-possible-renderer"));

var _noLongerPossibleRenderer = _interopRequireDefault(require("./no-longer-possible-renderer"));

var _notYetCalculatedRenderer = _interopRequireDefault(require("./not-yet-calculated-renderer"));

var _snoozedRenderer = _interopRequireDefault(require("./snoozed-renderer"));

var _upcomingTripRenderer = _interopRequireDefault(require("./upcoming-trip-renderer"));

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

/**
 * Uses the strategy pattern to calculate various pieces of data about a
 * monitored trip based off of whether it is in one of the following states:
 * - not yet calculated by the otp-middleware trip monitor
 * - set to be inactive (the trip monitor won't check it) by the user
 * - snoozed for the day by the user
 * - being no longer possible (the matching itinerary wasn't found for a whole
 *    week)
 * - the next trip isn't possible (other days might still be possible)
 * - the next trip will happen at some point in the future (in this state, the
 *    trip monitor might have already calculated some realtime data)
 * - the trip is active (currently in progress)
 */
function getRenderData(props) {
  const {
    monitoredTrip
  } = props;
  const journeyState = monitoredTrip && monitoredTrip.journeyState;
  let data;

  if (!monitoredTrip || !journeyState) {
    data = (0, _notYetCalculatedRenderer.default)();
  } else if (!monitoredTrip.isActive) {
    data = (0, _inactiveRenderer.default)(monitoredTrip);
  } else if (monitoredTrip.snoozed) {
    data = (0, _snoozedRenderer.default)(monitoredTrip);
  } else if (journeyState.tripStatus === 'NO_LONGER_POSSIBLE') {
    data = (0, _noLongerPossibleRenderer.default)(monitoredTrip);
  } else if (journeyState.tripStatus === 'NEXT_TRIP_NOT_POSSIBLE') {
    data = (0, _nextTripNotPossibleRenderer.default)(monitoredTrip);
  } else if (journeyState.tripStatus === 'TRIP_UPCOMING') {
    data = (0, _upcomingTripRenderer.default)(props);
  } else if (journeyState.tripStatus === 'TRIP_ACTIVE') {
    data = (0, _activeTripRenderer.default)(props);
  } else {
    // trip status not yet calculated
    data = (0, _notYetCalculatedRenderer.default)(monitoredTrip);
  }

  return data;
}

module.exports = exports.default;

//# sourceMappingURL=index.js