"use strict";

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

exports.__esModule = true;
exports.formatSeconds = formatSeconds;
exports.formatTime = formatTime;
exports.getProcessedPercentage = getProcessedPercentage;
exports.KEY_CODE = void 0;

var _moment = _interopRequireDefault(require("moment"));

function formatSeconds(sec) {
  return formatTime(sec, 'seconds');
}

function formatTime(amount, unit) {
  var duration = _moment.default.duration(amount, unit);

  var hours = Math.floor(duration.hours());
  var result = zerofill(Math.floor(duration.minutes())) + ':' + zerofill(Math.floor(duration.seconds()));

  if (hours >= 1) {
    result = hours + ':' + result;
  }

  return result;
}

function zerofill(value, prefix) {
  if (prefix === void 0) {
    prefix = '00';
  }

  return (prefix + value).slice(-prefix.length);
}

function getProcessedPercentage(prcessedDistance, totalWidth, indicatorRadius) {
  var processPercentage = 0;

  if (prcessedDistance < indicatorRadius) {
    processPercentage = 0;
  } else if (prcessedDistance > totalWidth - indicatorRadius) {
    processPercentage = 1;
  } else {
    processPercentage = (prcessedDistance - indicatorRadius) / (totalWidth - indicatorRadius * 2);
  }

  return processPercentage;
}

var KEY_CODE = Object.freeze({
  LEFT: 37,
  UP: 38,
  RIGHT: 39,
  DOWN: 40,
  END: 35,
  HOME: 36,
  PAGEUP: 33,
  PAGEDOWN: 34
});
exports.KEY_CODE = KEY_CODE;