import Vue from 'vue';
import { FormatMode } from '../../../utils/i18n/i18n';
import { dateFilter } from '../date/date';
var oneMinuteInMillisecond = 60 * 1000;
var oneHourInMillisecond = 60 * oneMinuteInMillisecond;
var oneDayInMillisecond = 24 * oneHourInMillisecond;
var thirtyOneDaysInMillisecond = 31 * oneDayInMillisecond;
var averageExecutionMillisecondTime = 900;
var TimeElapsedFilter = /** @class */ (function () {
    function TimeElapsedFilter() {
    }
    TimeElapsedFilter.format = function (date, firstLetterUppercase) {
        if (firstLetterUppercase === void 0) { firstLetterUppercase = false; }
        var timeElapsed;
        var shortModeParams = { shortMode: true };
        var i18nStartKey = firstLetterUppercase ? 'f-m-time-elapsed-start-sentence:' : 'f-m-time-elapsed:';
        var calculateTimeElapsed = (new Date().getTime() + averageExecutionMillisecondTime) - date.getTime();
        if (Math.sign(calculateTimeElapsed) !== 1) {
            throw new Error('Date is in the future');
        }
        if (calculateTimeElapsed < oneMinuteInMillisecond) {
            timeElapsed = TimeElapsedFilter.translateDate(i18nStartKey + 'now', {});
        }
        else if (calculateTimeElapsed < oneHourInMillisecond) {
            timeElapsed = TimeElapsedFilter.defineLessThanOneHourMessage(calculateTimeElapsed, i18nStartKey);
        }
        else if (calculateTimeElapsed < oneDayInMillisecond) {
            timeElapsed = TimeElapsedFilter.defineLessThanOneDayMessage(calculateTimeElapsed, i18nStartKey);
        }
        else if (calculateTimeElapsed < thirtyOneDaysInMillisecond) {
            timeElapsed = TimeElapsedFilter.defineLessThanThirtyOneDaysMessage(calculateTimeElapsed, i18nStartKey);
        }
        else {
            timeElapsed = dateFilter(date, shortModeParams);
        }
        return timeElapsed;
    };
    TimeElapsedFilter.defineLessThanOneHourMessage = function (calculateTimeElapsed, i18nStartKey) {
        var minute = Math.floor(calculateTimeElapsed / oneMinuteInMillisecond);
        return TimeElapsedFilter.translateDate(i18nStartKey + 'minute', { minute: minute }, minute);
    };
    TimeElapsedFilter.defineLessThanOneDayMessage = function (calculateTimeElapsed, i18nStartKey) {
        var hour = Math.floor(calculateTimeElapsed / oneHourInMillisecond);
        return TimeElapsedFilter.translateDate(i18nStartKey + 'hour', { hour: hour }, hour);
    };
    TimeElapsedFilter.defineLessThanThirtyOneDaysMessage = function (calculateTimeElapsed, i18nStartKey) {
        var day = Math.floor(calculateTimeElapsed / oneDayInMillisecond);
        return TimeElapsedFilter.translateDate(i18nStartKey + 'day', { day: day }, day);
    };
    TimeElapsedFilter.translateDate = function (key, params, timeNumber) {
        return (Vue.prototype).$i18n.translate(key, params, timeNumber, '', undefined, FormatMode.Vsprintf);
    };
    return TimeElapsedFilter;
}());
export { TimeElapsedFilter };
//# sourceMappingURL=time-elapsed.js.map