'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.formatTimespan = undefined;
var _default_ar_number = Intl.NumberFormat('ar', { 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;

  return _s = hours, _n = +_s, (_n === 1 ? _default_ar_number(hours) + ' \u0633\u0627\u0639\u0629' : _default_ar_number(hours) + ' \u0633\u0627\u0639\u0627\u062A');
};

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

  return _s2 = minutes, _n2 = +_s2, (_n2 === 1 ? _default_ar_number(minutes) + ' \u062F\u0642\u064A\u0642\u0629' : _default_ar_number(minutes) + ' \u062F\u0642\u0627\u0626\u0642');
};

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

  return _s3 = seconds, _n3 = +_s3, (_n3 === 1 ? _default_ar_number(seconds) + ' \u062B\u0627\u0646\u064A\u0629' : _default_ar_number(seconds) + ' \u062B\u0648\u0627\u0646\u064D');
};

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