import Vue from 'vue';
import { FormatMode } from '../../../utils/i18n/i18n';
import ModulDate, { DatePrecision } from '../../../utils/modul-date/modul-date';
import { dateFilter } from '../date/date';
export var MFormatMode;
(function (MFormatMode) {
    MFormatMode["LongMonth"] = "long-month";
    MFormatMode["ShortMonth"] = "short-month";
})(MFormatMode || (MFormatMode = {}));
var PeriodFilter = /** @class */ (function () {
    function PeriodFilter() {
    }
    PeriodFilter.formatPeriod = function (period, formatMode) {
        var formattedPeriod;
        var shortModeParams = {};
        if (formatMode === MFormatMode.ShortMonth) {
            shortModeParams = { shortMode: true };
        }
        if (period.start && period.end) {
            formattedPeriod = PeriodFilter.compactStartAndEndDate(period.start, period.end, shortModeParams);
        }
        else if (period.start && !period.end) {
            formattedPeriod = PeriodFilter.onlyStartDate(period.start, shortModeParams);
        }
        else if (period.end && !period.start) {
            formattedPeriod = PeriodFilter.onlyEndDate(period.end, shortModeParams);
        }
        else {
            throw new Error('Period must have at least one Date');
        }
        return formattedPeriod;
    };
    PeriodFilter.compactStartAndEndDate = function (start, end, shortModeParams) {
        var startDate = new ModulDate(start);
        var endDate = new ModulDate(end);
        var formattedPeriod;
        if (startDate.isSame(endDate, DatePrecision.DAY)) {
            var startFormatted = dateFilter(start, shortModeParams);
            formattedPeriod = this.translateDate('f-m-period:sameDay', { date: startFormatted });
        }
        else if (startDate.isSame(endDate, DatePrecision.MONTH)) {
            formattedPeriod = this.startAndEndDateSameMonth(start, end, shortModeParams);
        }
        else if (startDate.isSame(endDate, DatePrecision.YEAR)) {
            formattedPeriod = this.startAndEndDateSameYear(start, end, shortModeParams);
        }
        else {
            formattedPeriod = this.fullStartAndEndDate(start, end, shortModeParams);
        }
        return formattedPeriod;
    };
    PeriodFilter.onlyStartDate = function (start, shortModeParams) {
        var startFormatted = dateFilter(start, shortModeParams);
        return this.translateDate('f-m-period:start', { start: startFormatted });
    };
    PeriodFilter.onlyEndDate = function (end, shortModeParams) {
        var endFormatted = dateFilter(end, shortModeParams);
        return this.translateDate('f-m-period:end', { end: endFormatted });
    };
    PeriodFilter.startAndEndDateSameMonth = function (start, end, shortModeParams) {
        var endFormatted = dateFilter(end, shortModeParams);
        var monthParams = { showMonth: false, showYear: false };
        var dateFilterParams = Object.assign(shortModeParams, monthParams);
        var startFormatted = dateFilter(start, dateFilterParams);
        var params = {
            start: startFormatted,
            end: endFormatted
        };
        return this.translateDate('f-m-period:dates', params);
    };
    PeriodFilter.startAndEndDateSameYear = function (start, end, shortModeParams) {
        var endFormatted = dateFilter(end, shortModeParams);
        var monthParams = { showYear: false };
        var dateFilterParams = Object.assign(shortModeParams, monthParams);
        var startFormatted = dateFilter(start, dateFilterParams);
        var params = {
            start: startFormatted,
            end: endFormatted
        };
        return this.translateDate('f-m-period:dates', params);
    };
    PeriodFilter.fullStartAndEndDate = function (start, end, shortModeParams) {
        var startFormatted = dateFilter(start, shortModeParams);
        var endFormatted = dateFilter(end, shortModeParams);
        var params = {
            start: startFormatted,
            end: endFormatted
        };
        return this.translateDate('f-m-period:dates', params);
    };
    PeriodFilter.translateDate = function (key, params) {
        return (Vue.prototype).$i18n.translate(key, params, 0, '', undefined, FormatMode.Vsprintf);
    };
    return PeriodFilter;
}());
export { PeriodFilter };
//# sourceMappingURL=period.js.map