import { DatePreFilter } from '../../../model/common-model';
import moment from "moment";
var DateComputation = (function () {
    function DateComputation() {
    }
    DateComputation.prototype.GetDateIntervalFromFilter = function (filter) {
        var isDateFromLocked = false, isDateToLocked = false;
        var dateFrom, dateTo;
        var today = moment();
        if ((filter === null || filter === void 0 ? void 0 : filter.datePreFilter) != null) {
            switch (filter.datePreFilter) {
                case DatePreFilter.Today:
                    dateFrom = moment(today).startOf("day");
                    dateTo = moment(today).endOf("day");
                    break;
                case DatePreFilter.Past:
                    if (filter.includeToday) {
                        dateTo = moment(today).endOf("day");
                    }
                    else {
                        dateTo = moment(today).subtract(1, "day").endOf("day");
                    }
                    isDateFromLocked = true;
                    break;
                case DatePreFilter.Futur:
                    if (filter.includeToday) {
                        dateFrom = moment(today).startOf("day");
                    }
                    else {
                        dateFrom = moment(today).add(1, "day").startOf("day");
                    }
                    isDateToLocked = true;
                    break;
            }
        }
        else if ((filter === null || filter === void 0 ? void 0 : filter.dateFrom) != null || (filter === null || filter === void 0 ? void 0 : filter.dateTo) != null) {
            if (filter.dateFrom != null) {
                dateFrom = moment(filter.dateFrom).startOf("day");
            }
            if (filter.dateTo != null) {
                dateTo = moment(filter.dateTo).endOf("day");
            }
        }
        if ((filter === null || filter === void 0 ? void 0 : filter.isThisMonth) != null || (filter === null || filter === void 0 ? void 0 : filter.isThisWeek) != null || (filter === null || filter === void 0 ? void 0 : filter.isLastMonth) != null ||
            (filter === null || filter === void 0 ? void 0 : filter.isLastWeek) != null || (filter === null || filter === void 0 ? void 0 : filter.isNextMonth) != null || (filter === null || filter === void 0 ? void 0 : filter.isNextWeek) != null) {
            if (filter.isThisMonth) {
                dateFrom = this.addMomentToMoment(moment(today).startOf("month"), dateFrom, true, isDateFromLocked);
                dateTo = this.addMomentToMoment(moment(today).endOf("month"), dateTo, false, isDateToLocked);
            }
            else if (filter.isThisWeek) {
                dateFrom = this.addMomentToMoment(moment(today).startOf("week"), dateFrom, true, isDateFromLocked);
                dateTo = this.addMomentToMoment(moment(today).endOf("week"), dateTo, false, isDateToLocked);
            }
            if (filter.isLastMonth) {
                dateFrom = this.addMomentToMoment(moment(today).subtract(1, "month").startOf("month"), dateFrom, true, isDateFromLocked);
                dateTo = this.addMomentToMoment(moment(today).subtract(1, "month").endOf("month"), dateTo, false, isDateToLocked);
            }
            else if (filter.isLastWeek) {
                dateFrom = this.addMomentToMoment(moment(today).subtract(1, "week").startOf("week"), dateFrom, true, isDateFromLocked);
                dateTo = this.addMomentToMoment(moment(today).subtract(1, "week").endOf("week"), dateTo, false, isDateToLocked);
            }
            if (filter.isNextMonth) {
                dateFrom = this.addMomentToMoment(moment(today).add(1, "month").startOf("month"), dateFrom, true, isDateFromLocked);
                dateTo = this.addMomentToMoment(moment(today).add(1, "month").endOf("month"), dateTo, false, isDateToLocked);
            }
            else if (filter.isNextWeek) {
                dateFrom = this.addMomentToMoment(moment(today).add(1, "week").startOf("week"), dateFrom, true, isDateFromLocked);
                dateTo = this.addMomentToMoment(moment(today).add(1, "week").endOf("week"), dateTo, false, isDateToLocked);
            }
        }
        return { dateFrom: dateFrom != null ? dateFrom.add(dateFrom.utcOffset(), "minutes") : dateFrom, dateTo: dateTo };
    };
    DateComputation.prototype.addMomentToMoment = function (dateToAdd, date, isBefore, isDateLocked) {
        if (isDateLocked === void 0) { isDateLocked = false; }
        if (!isDateLocked) {
            if (date == null) {
                date = dateToAdd;
            }
            else {
                if (isBefore) {
                    if (dateToAdd < date) {
                        date = dateToAdd;
                    }
                }
                else {
                    if (dateToAdd > date) {
                        date = dateToAdd;
                    }
                }
            }
        }
        return date;
    };
    return DateComputation;
}());
export { DateComputation };

//# sourceMappingURL=date-computation.js.map
