import { __assign } from "tslib";
import Vue from 'vue';
import { FormatMode } from '../../../utils/i18n/i18n';
import ModulDate, { DatePrecision } from '../../../utils/modul-date/modul-date';
import { DateTimeFilter } from '../date-time/date-time';
import { dateFilter } from '../date/date';
import { timePeriodFilter } from '../time/time';
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, withTime) {
        if (withTime === void 0) { withTime = false; }
        var formattedPeriod;
        var filterParams = {
            shortMode: formatMode === MFormatMode.ShortMonth,
            withTime: withTime
        };
        if (period.start && period.end) {
            formattedPeriod = PeriodFilter.compactStartAndEndDate(period.start, period.end, filterParams);
        }
        else if (period.start && !period.end) {
            formattedPeriod = PeriodFilter.onlyStartDate(period.start, filterParams);
        }
        else if (period.end && !period.start) {
            formattedPeriod = PeriodFilter.onlyEndDate(period.end, filterParams);
        }
        else {
            throw new Error('Period must have at least one Date');
        }
        return formattedPeriod;
    };
    PeriodFilter.onlyStartDate = function (start, filterParams) {
        var startFormatted = dateFilter(start, filterParams);
        return this.translateDate('f-m-period:start', { start: startFormatted });
    };
    PeriodFilter.onlyEndDate = function (end, filterParams) {
        var endFormatted = dateFilter(end, filterParams);
        return this.translateDate('f-m-period:end', { end: endFormatted });
    };
    PeriodFilter.compactStartAndEndDate = function (start, end, filterParams) {
        var startDate = new ModulDate(start);
        var endDate = new ModulDate(end);
        var formattedPeriod;
        if (startDate.isSame(endDate, DatePrecision.DAY)) {
            formattedPeriod = this.sameDay(start, end, filterParams);
        }
        else if (startDate.isSame(endDate, DatePrecision.MONTH) && (!filterParams || !filterParams.withTime)) {
            formattedPeriod = this.startAndEndDateSameMonth(start, end, filterParams);
        }
        else if (startDate.isSame(endDate, DatePrecision.YEAR)) {
            formattedPeriod = this.startAndEndDateSameYear(start, end, filterParams);
        }
        else {
            formattedPeriod = this.fullStartAndEndDate(start, end, filterParams);
        }
        return formattedPeriod;
    };
    PeriodFilter.sameDay = function (start, end, filterParams) {
        var time = timePeriodFilter({ from: start, to: end }, { preposition: true });
        var params = {
            date: dateFilter(start, filterParams),
            time: (time.length > 0) ? time.charAt(0).toLowerCase() + time.slice(1) : ''
        };
        if (filterParams && filterParams.withTime) {
            return this.translateDate('f-m-period:sameDayShowTime', params);
        }
        return this.translateDate('f-m-period:sameDay', params);
    };
    PeriodFilter.startAndEndDateSameMonth = function (startDate, endDate, filterParams) {
        var start = this.getTranslateDateParams(startDate, __assign(__assign({}, filterParams), { showMonth: false, showYear: false }));
        var end = this.getTranslateDateParams(endDate, filterParams);
        return this.translateDate('f-m-period:dates', { start: start, end: end });
    };
    PeriodFilter.startAndEndDateSameYear = function (startDate, endDate, filterParams) {
        var start = this.getTranslateDateParams(startDate, __assign(__assign({}, filterParams), { showYear: false }));
        var end = this.getTranslateDateParams(endDate, filterParams);
        return this.translateDate('f-m-period:dates', { start: start, end: end });
    };
    PeriodFilter.fullStartAndEndDate = function (startDate, endDate, filterParams) {
        var start = this.getTranslateDateParams(startDate, filterParams);
        var end = this.getTranslateDateParams(endDate, filterParams);
        return this.translateDate('f-m-period:dates', { start: start, end: end });
    };
    PeriodFilter.getTranslateDateParams = function (date, filterParams) {
        if (filterParams && filterParams.withTime) {
            return DateTimeFilter.formatDateTime(date, filterParams);
        }
        return dateFilter(date, filterParams);
    };
    PeriodFilter.translateDate = function (key, params) {
        return (Vue.prototype).$i18n.translate(key, params, 0, '', undefined, FormatMode.Vsprintf);
    };
    return PeriodFilter;
}());
export { PeriodFilter };
//# sourceMappingURL=period.js.map