/**
 * DevExtreme (esm/__internal/scheduler/workspaces/view_model/m_view_data_generator_month.js)
 * Version: 23.2.6 (build 24140-0112)
 * Build date: Sun May 19 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import dateUtils from "../../../../core/utils/date";
import dateLocalization from "../../../../localization/date";
import {
    getToday,
    isFirstCellInMonthWithIntervalCount,
    monthUtils,
    setOptionHour
} from "../../../scheduler/r1/utils/index";
import timezoneUtils from "../../m_utils_time_zone";
import {
    calculateAlignedWeeksBetweenDates
} from "./m_utils";
import {
    ViewDataGenerator
} from "./m_view_data_generator";
var toMs = dateUtils.dateToMilliseconds;
var DAYS_IN_WEEK = 7;
export class ViewDataGeneratorMonth extends ViewDataGenerator {
    constructor() {
        super(...arguments);
        this.tableAllDay = void 0
    }
    getCellData(rowIndex, columnIndex, options, allDay) {
        var {
            indicatorTime: indicatorTime,
            timeZoneCalculator: timeZoneCalculator,
            intervalCount: intervalCount,
            viewOffset: viewOffset
        } = options;
        var data = super.getCellData(rowIndex, columnIndex, options, false);
        var startDate = timezoneUtils.addOffsetsWithoutDST(data.startDate, -viewOffset);
        data.today = this.isCurrentDate(startDate, indicatorTime, timeZoneCalculator);
        data.otherMonth = this.isOtherMonth(startDate, this._minVisibleDate, this._maxVisibleDate);
        data.firstDayOfMonth = isFirstCellInMonthWithIntervalCount(startDate, intervalCount);
        data.text = monthUtils.getCellText(startDate, intervalCount);
        return data
    }
    isCurrentDate(date, indicatorTime, timeZoneCalculator) {
        return dateUtils.sameDate(date, getToday(indicatorTime, timeZoneCalculator))
    }
    isOtherMonth(cellDate, minDate, maxDate) {
        return !dateUtils.dateInRange(cellDate, minDate, maxDate, "date")
    }
    _calculateCellIndex(rowIndex, columnIndex, rowCount, columnCount) {
        return monthUtils.calculateCellIndex(rowIndex, columnIndex, rowCount, columnCount)
    }
    calculateEndDate(startDate, interval, endDayHour) {
        return setOptionHour(startDate, endDayHour)
    }
    getInterval() {
        return toMs("day")
    }
    _calculateStartViewDate(options) {
        return monthUtils.calculateStartViewDate(options.currentDate, options.startDayHour, options.startDate, options.intervalCount, this.getFirstDayOfWeek(options.firstDayOfWeek))
    }
    _setVisibilityDates(options) {
        var {
            intervalCount: intervalCount,
            startDate: startDate,
            currentDate: currentDate
        } = options;
        var firstMonthDate = dateUtils.getFirstMonthDate(startDate);
        var viewStart = monthUtils.getViewStartByOptions(startDate, currentDate, intervalCount, firstMonthDate);
        this._minVisibleDate = new Date(viewStart.setDate(1));
        var nextMonthDate = new Date(viewStart.setMonth(viewStart.getMonth() + intervalCount));
        this._maxVisibleDate = new Date(nextMonthDate.setDate(0))
    }
    getCellCount() {
        return DAYS_IN_WEEK
    }
    getRowCount(options) {
        var _a;
        var startDate = new Date(options.currentDate);
        startDate.setDate(1);
        var endDate = new Date(startDate);
        endDate.setMonth(endDate.getMonth() + options.intervalCount);
        endDate.setDate(0);
        return calculateAlignedWeeksBetweenDates(startDate, endDate, null !== (_a = options.firstDayOfWeek) && void 0 !== _a ? _a : dateLocalization.firstDayOfWeekIndex())
    }
    getCellCountInDay() {
        return 1
    }
    setHiddenInterval() {
        this.hiddenInterval = 0
    }
    getCellEndDate(cellStartDate, options) {
        var {
            startDayHour: startDayHour,
            endDayHour: endDayHour
        } = options;
        var durationMs = (endDayHour - startDayHour) * toMs("hour");
        return timezoneUtils.addOffsetsWithoutDST(cellStartDate, durationMs)
    }
}
