"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

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

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

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-common/lib/format-message"));

var _withI18nSupport2 = _interopRequireDefault(require("@instructure/quiz-common/lib/with-i18n-support"));

var ElapsedTime =
/*#__PURE__*/
function (_withI18nSupport) {
  (0, _inherits2.default)(ElapsedTime, _withI18nSupport);

  function ElapsedTime() {
    (0, _classCallCheck2.default)(this, ElapsedTime);
    return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(ElapsedTime).apply(this, arguments));
  }

  (0, _createClass2.default)(ElapsedTime, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          eventTime = _this$props.eventTime,
          startTime = _this$props.startTime;
      var difference = eventTime - startTime;
      var totalSeconds = difference / 1000;
      var hours = Math.floor(totalSeconds / 3600);
      var remainder = totalSeconds - hours * 3600;
      var minutes = Math.floor(remainder / 60);
      var seconds = remainder - minutes * 60; // Intl.DurationFormat doesn't exist yet.
      // https://github.com/tc39/ecma402/issues/47
      // Let translators provide patterns for durations

      var displayTime = hours ? this.formatDecimal2MinIntegerNoFraction(hours) + ":" + this.formatDecimal2MinIntegerNoFraction(minutes) + ":" + this.formatDecimal2MinIntegerNoFraction(seconds) : this.formatDecimal2MinIntegerNoFraction(minutes) + ":" + this.formatDecimal2MinIntegerNoFraction(seconds);
      return _react.default.createElement("span", null, displayTime);
    }
  }]);
  ElapsedTime.displayName = "ElapsedTime";
  return ElapsedTime;
}((0, _withI18nSupport2.default)(_react.Component));

exports.default = ElapsedTime;
ElapsedTime.propTypes = {
  eventTime: _propTypes.default.instanceOf(Date).isRequired,
  startTime: _propTypes.default.instanceOf(Date).isRequired,
  locale: _propTypes.default.string
};
ElapsedTime.defaultProps = {
  locale: null
};
ElapsedTime.contextTypes = {
  locale: _propTypes.default.string
};