/**
 * DevExtreme (esm/__internal/scheduler/workspaces/view_model/m_utils.js)
 * Version: 23.1.6 (build 23316-0110)
 * Build date: Sun Nov 12 2023
 *
 * Copyright (c) 2012 - 2023 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import dateUtils from "../../../../core/utils/date";
import {
    VIEWS
} from "../../m_constants";
import {
    ViewDataGenerator
} from "./m_view_data_generator";
import {
    ViewDataGeneratorDay
} from "./m_view_data_generator_day";
import {
    ViewDataGeneratorMonth
} from "./m_view_data_generator_month";
import {
    ViewDataGeneratorTimelineMonth
} from "./m_view_data_generator_timeline_month";
import {
    ViewDataGeneratorWeek
} from "./m_view_data_generator_week";
import {
    ViewDataGeneratorWorkWeek
} from "./m_view_data_generator_work_week";
var DAYS_IN_WEEK = 7;
var MS_IN_DAY = 864e5;
export var getViewDataGeneratorByViewType = viewType => {
    switch (viewType) {
        case VIEWS.MONTH:
            return new ViewDataGeneratorMonth;
        case VIEWS.TIMELINE_MONTH:
            return new ViewDataGeneratorTimelineMonth;
        case VIEWS.DAY:
        case VIEWS.TIMELINE_DAY:
            return new ViewDataGeneratorDay;
        case VIEWS.WEEK:
        case VIEWS.TIMELINE_WEEK:
            return new ViewDataGeneratorWeek;
        case VIEWS.WORK_WEEK:
        case VIEWS.TIMELINE_WORK_WEEK:
            return new ViewDataGeneratorWorkWeek;
        default:
            return new ViewDataGenerator
    }
};
export function alignToFirstDayOfWeek(date, firstDayOfWeek) {
    var newDate = new Date(date);
    var dayDiff = newDate.getDay() - firstDayOfWeek;
    if (dayDiff < 0) {
        dayDiff += DAYS_IN_WEEK
    }
    newDate.setDate(newDate.getDate() - dayDiff);
    return newDate
}
export function alignToLastDayOfWeek(date, firstDayOfWeek) {
    var newDate = alignToFirstDayOfWeek(date, firstDayOfWeek);
    newDate.setDate(newDate.getDate() + DAYS_IN_WEEK - 1);
    return newDate
}
export function calculateDaysBetweenDates(fromDate, toDate) {
    var msDiff = dateUtils.trimTime(toDate).getTime() - dateUtils.trimTime(fromDate).getTime();
    return Math.round(msDiff / MS_IN_DAY) + 1
}
export function calculateAlignedWeeksBetweenDates(fromDate, toDate, firstDayOfWeek) {
    var alignedFromDate = alignToFirstDayOfWeek(fromDate, firstDayOfWeek);
    var alignedToDate = alignToLastDayOfWeek(toDate, firstDayOfWeek);
    var weekCount = calculateDaysBetweenDates(alignedFromDate, alignedToDate) / DAYS_IN_WEEK;
    return Math.max(weekCount, 6)
}
