"use strict";

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

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

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

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

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

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

var _formattedDuration = _interopRequireDefault(require("../util/formatted-duration"));

var _icon = _interopRequireDefault(require("../util/icon"));

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

class RealtimeAnnotation extends _react.Component {
  render() {
    const {
      componentClass,
      realtimeEffects,
      toggleRealtime,
      useRealtime
    } = this.props; // Keep only the unique route IDs (so that duplicates are not listed).

    const filteredRoutes = realtimeEffects.normalRoutes.filter((routeId, index, self) => self.indexOf(routeId) === index); // FIXME: there are some weird css things happening in desktop vs. mobile,
    // so I removed the divs with classNames and opted for h4 and p for now

    const innerContent = /*#__PURE__*/_react.default.createElement("div", {
      className: "realtime-alert"
    }, /*#__PURE__*/_react.default.createElement("div", {
      className: "content"
    }, /*#__PURE__*/_react.default.createElement("h3", null, /*#__PURE__*/_react.default.createElement(_icon.default, {
      type: "exclamation-circle",
      withSpace: true
    }), /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: "components.RealtimeAnnotation.serviceUpdate"
    })), /*#__PURE__*/_react.default.createElement("p", {
      className: "small"
    }, useRealtime ? /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: "components.RealtimeAnnotation.delaysShownInResults",
      values: {
        normalDuration: /*#__PURE__*/_react.default.createElement("strong", null, /*#__PURE__*/_react.default.createElement(_formattedDuration.default, {
          duration: realtimeEffects.normalDuration
        })),
        routes: /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedList, {
          type: "conjunction",
          value: filteredRoutes.map(route => /*#__PURE__*/_react.default.createElement("strong", null, route))
        })
      }
    }) : /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: "components.RealtimeAnnotation.delaysNotShownInResults"
    })), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
      block: componentClass === 'popover' // display as block in popover
      ,
      className: "toggle-realtime",
      onClick: toggleRealtime
    }, useRealtime ? /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: "components.RealtimeAnnotation.ignoreServiceDelays"
    }) : /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: "components.RealtimeAnnotation.applyServiceDelays"
    })))));

    if (componentClass === 'popover') {
      return /*#__PURE__*/_react.default.createElement(_reactBootstrap.OverlayTrigger, {
        overlay: /*#__PURE__*/_react.default.createElement(_reactBootstrap.Popover, {
          id: "popover-positioned-bottom",
          style: {
            maxWidth: '300px'
          }
        }, innerContent),
        placement: "bottom",
        trigger: "click"
      }, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
        bsStyle: "link"
      }, /*#__PURE__*/_react.default.createElement("i", {
        className: "fa fa-2x fa-exclamation-circle"
      })));
    } else {
      return innerContent;
    }
  }

}

exports.default = RealtimeAnnotation;

_defineProperty(RealtimeAnnotation, "propTypes", {
  realtimeEffects: _propTypes.default.object,
  toggleRealtime: _propTypes.default.func,
  useRealtime: _propTypes.default.bool
});

module.exports = exports.default;

//# sourceMappingURL=realtime-annotation.js