'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.formatTimespan = undefined;
var _default_mi_number = Intl.NumberFormat('mi', { style: 'decimal' }).format;
exports.formatTime = formatTime;

var _formatMessage = require('../format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

var minuteDuration = 60;
var hourDuration = 3600;

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

  return _s = hours, _n = +_s, (_i = Math.floor(Math.abs(+_s)), _v = (_s + '.').split('.')[1].length, _i === 1 && _v === 0 ? _default_mi_number(hours) + ' haora' : _default_mi_number(hours) + ' ng\u0101 haora');
};

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

  return _s2 = minutes, _n2 = +_s2, (_i2 = Math.floor(Math.abs(+_s2)), _v2 = (_s2 + '.').split('.')[1].length, _i2 === 1 && _v2 === 0 ? _default_mi_number(minutes) + ' meneti' : _default_mi_number(minutes) + ' ng\u0101 meneti');
};

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

  return _s3 = seconds, _n3 = +_s3, (_i3 = Math.floor(Math.abs(+_s3)), _v3 = (_s3 + '.').split('.')[1].length, _i3 === 1 && _v3 === 0 ? _default_mi_number(seconds) + ' H\u0113kona' : _default_mi_number(seconds) + ' ng\u0101 h\u0113kona');
};

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

function formatTime(time) {
  var secondDuration = arguments.length > 1 && arguments[1] !== undefined ? 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);
}