"use strict";

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

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

var _itinerary = require("@opentripplanner/core-utils/lib/itinerary");

var _types = require("@opentripplanner/core-utils/lib/types");

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

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

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

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

var _realtimeStatusLabel = _interopRequireWildcard(require("../../viewers/realtime-status-label"));

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 }; }

const StyledStatusLabel = (0, _styledComponents.default)(_realtimeStatusLabel.default)`
  ${_realtimeStatusLabel.MainContent} {
    font-size: 80%;
    line-height: 1em;
  }
  ${_realtimeStatusLabel.DelayText} {
    display: block;
  }
`;
/**
 * This component displays the scheduled departure/arrival time for a leg,
 * and, for transit legs, displays any delays or earliness where applicable.
 */

function RealtimeTimeColumn({
  isDestination,
  leg,
  timeOptions
}) {
  const time = isDestination ? leg.endTime : leg.startTime;
  const formattedTime = time && (0, _time.formatTime)(time, timeOptions);
  const isTransitLeg = (0, _itinerary.isTransit)(leg.mode);
  const isRealtimeTransitLeg = isTransitLeg && leg.realTime; // For non-transit legs show only the scheduled time.

  if (!isTransitLeg) {
    return /*#__PURE__*/_react.default.createElement("div", null, formattedTime);
  }

  const delaySeconds = isDestination ? leg.arrivalDelay : leg.departureDelay;
  const originalTimeMillis = time - delaySeconds * 1000;
  const originalFormattedTime = originalTimeMillis && (0, _time.formatTime)(originalTimeMillis, timeOptions);
  return /*#__PURE__*/_react.default.createElement(StyledStatusLabel, {
    delay: delaySeconds,
    isRealtime: isRealtimeTransitLeg,
    originalTime: originalFormattedTime,
    time: formattedTime
  });
}

RealtimeTimeColumn.propTypes = {
  isDestination: _propTypes.default.bool.isRequired,
  leg: _types.legType.isRequired,
  timeOptions: _types.timeOptionsType
};
RealtimeTimeColumn.defaultProps = {
  timeOptions: null
};
var _default = RealtimeTimeColumn;
exports.default = _default;
module.exports = exports.default;

//# sourceMappingURL=realtime-time-column.js