"use strict";

exports.__esModule = true;
exports.secondsToPosition = exports.secondsToISO = exports.positionToSeconds = exports.MAX_SECONDS = void 0;
var ISOFormatHoursIndex = 11;
var ISOFormatMinutesIndex = 14;
var ISOFormatMinutesSingleDigitIndex = 15;
var ISOFormatHoursLength = 8;
var ISOFormatMinutesLength = 5;
var ISOFormatMinutesSingleDigitLength = 4;
var MAX_SECONDS = exports.MAX_SECONDS = 8640000000000; //  https://262.ecma-international.org/5.1/#sec-15.9.1.1

var validSeconds = seconds => {
  return seconds > MAX_SECONDS ? 0 : seconds;
};
var secondsToISO = (seconds, isLoaded, duration) => {
  if (!isLoaded) {
    return '--:--';
  }
  try {
    var durationMinutes = Math.floor(duration / 60);
    var durationHours = Math.floor(durationMinutes / 60);
    var secondsInISOFormat = new Date(validSeconds(seconds) * 1000).toISOString();
    if (durationHours > 0) {
      return secondsInISOFormat.substr(ISOFormatHoursIndex, ISOFormatHoursLength);
    }
    if (durationMinutes > 9) {
      return secondsInISOFormat.substr(ISOFormatMinutesIndex, ISOFormatMinutesLength);
    }
    return secondsInISOFormat.substr(ISOFormatMinutesSingleDigitIndex, ISOFormatMinutesSingleDigitLength);
  } catch (ex) {
    return '--:--';
  }
};
exports.secondsToISO = secondsToISO;
var positionToSeconds = (positionInPercentage, durationInSeconds) => positionInPercentage / 100 * durationInSeconds;
exports.positionToSeconds = positionToSeconds;
var secondsToPosition = (seekInSeconds, durationInSeconds) => seekInSeconds / durationInSeconds * 100;
exports.secondsToPosition = secondsToPosition;
//# sourceMappingURL=utils.js.map