import Vue from 'vue';
import { FormatMode } from '../../../utils/i18n/i18n';
import ModulDate, { DatePrecision } from '../../../utils/modul-date/modul-date';
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.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)) {
            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.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.startAndEndDateSameMonth = function (start, end, filterParams) {
        var endFormatted = dateFilter(end, filterParams);
        var monthParams = { showMonth: false, showYear: false };
        var dateFilterParams = Object.assign(filterParams, 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, filterParams) {
        var endFormatted = dateFilter(end, filterParams);
        var monthParams = { showYear: false };
        var dateFilterParams = Object.assign(filterParams, 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, filterParams) {
        var startFormatted = dateFilter(start, filterParams);
        var endFormatted = dateFilter(end, filterParams);
        var params = {
            start: startFormatted,
            end: endFormatted
        };
        return this.translateDate('f-m-period:dates', params);
    };
    PeriodFilter.sameDay = function (start, end, filterParams) {
        var timeRange = {
            from: start,
            to: end
        };
        var time = timePeriodFilter(timeRange, { 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);
        }
        else {
            return this.translateDate('f-m-period:sameDay', 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