"use strict";

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

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

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

var _default_mi_number = Intl.NumberFormat("mi", { style: "decimal" }).format;
var minuteDuration = 60;
var hourDuration = 3600;

var formatHours = function formatHours(hours) {
  var _s, _n;

  return _default_mi_number(hours) + " ng\u0101 haora";
};

var formatMinutes = function formatMinutes(minutes) {
  var _s2, _n2;

  return _default_mi_number(minutes) + " ng\u0101 meneti";
};

var formatSeconds = function formatSeconds(seconds) {
  var _s3, _n3;

  return _default_mi_number(seconds) + " ng\u0101 h\u0113kona";
};

var formatTimespan = function formatTimespan(startTime, endTime) {
  return formatTime(endTime - startTime, 1000);
};

exports.formatTimespan = formatTimespan;

function formatTime(time) {
  var secondDuration = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
  var totalSeconds = Math.floor(time / secondDuration);
  var parts = [];
  var hours = Math.floor(totalSeconds / hourDuration);

  if (hours !== 0) {
    parts.push(formatHours(hours));
  }

  var minutes = Math.floor(totalSeconds / minuteDuration) % minuteDuration;

  if (minutes !== 0) {
    parts.push(formatMinutes(minutes));
  }

  var seconds = totalSeconds % minuteDuration;

  if (seconds !== 0 || parts.length === 0) {
    parts.push(formatSeconds(seconds));
  }

  var separator = " ";
  return parts.join(separator);
}