/**
 * DevExtreme (renovation/ui/scheduler/model/appointments.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/
 */
"use strict";
exports.getAppointmentsModel = exports.getAppointmentsConfig = void 0;
var _m_position_helper = require("../../../../__internal/scheduler/workspaces/helpers/m_position_helper");
var _m_utils = require("../../../../__internal/scheduler/resources/m_utils");
var _utils = require("../workspaces/utils");
var _date = _interopRequireDefault(require("../../../../core/utils/date"));
var _base = require("../view_model/to_test/views/utils/base");
var _utils2 = require("./utils");

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}

function _extends() {
    _extends = Object.assign ? Object.assign.bind() : function(target) {
        for (var i = 1; i < arguments.length; i++) {
            var source = arguments[i];
            for (var key in source) {
                if (Object.prototype.hasOwnProperty.call(source, key)) {
                    target[key] = source[key]
                }
            }
        }
        return target
    };
    return _extends.apply(this, arguments)
}
var toMs = function(name) {
    return _date.default.dateToMilliseconds(name)
};
var getAppointmentsConfig = function(schedulerConfig, viewConfig, loadedResources, viewDataProvider, isAllDayPanelSupported) {
    var groupCount = (0, _m_utils.getGroupCount)(loadedResources);
    var startViewDate = viewDataProvider.getStartViewDate();
    var dateRange = [startViewDate, viewDataProvider.getLastViewDateByEndDayHour(viewConfig.endDayHour)];
    return {
        adaptivityEnabled: schedulerConfig.adaptivityEnabled,
        rtlEnabled: schedulerConfig.rtlEnabled,
        resources: schedulerConfig.resources,
        timeZone: schedulerConfig.timeZone,
        groups: schedulerConfig.groups,
        startDayHour: viewConfig.startDayHour,
        viewStartDayHour: viewConfig.startDayHour,
        endDayHour: viewConfig.endDayHour,
        viewEndDayHour: viewConfig.endDayHour,
        currentDate: viewConfig.currentDate,
        isVirtualScrolling: "virtual" === viewConfig.scrolling.mode,
        intervalCount: viewConfig.intervalCount,
        hoursInterval: viewConfig.hoursInterval,
        showAllDayPanel: viewConfig.showAllDayPanel,
        allDayPanelMode: viewConfig.allDayPanelMode,
        supportAllDayRow: isAllDayPanelSupported,
        groupOrientation: viewDataProvider.getViewOptions().groupOrientation,
        firstDayOfWeek: viewConfig.firstDayOfWeek,
        viewType: viewConfig.type,
        cellDurationInMinutes: viewConfig.cellDuration,
        maxAppointmentsPerCell: viewConfig.maxAppointmentsPerCell,
        isVerticalGroupOrientation: viewDataProvider.getViewOptions().isVerticalGrouping,
        groupByDate: viewDataProvider.getViewOptions().isGroupedByDate,
        startViewDate: startViewDate,
        loadedResources: loadedResources,
        appointmentCountPerCell: 2,
        appointmentOffset: 26,
        allowResizing: false,
        allowAllDayResizing: false,
        dateTableOffset: 0,
        groupCount: groupCount,
        dateRange: dateRange
    }
};
exports.getAppointmentsConfig = getAppointmentsConfig;
var getAppointmentsModel = function(appointmentsConfig, viewDataProvider, timeZoneCalculator, dataAccessors, cellsMetaData) {
    var groupedByDate = (0, _utils.isGroupingByDate)(appointmentsConfig.groups, appointmentsConfig.groupOrientation, appointmentsConfig.groupByDate);
    var groupCount = appointmentsConfig.groupCount,
        isVerticalGroupOrientation = appointmentsConfig.isVerticalGroupOrientation;
    var positionHelper = new _m_position_helper.PositionHelper({
        viewDataProvider: viewDataProvider,
        groupedByDate: groupedByDate,
        rtlEnabled: appointmentsConfig.rtlEnabled,
        groupCount: groupCount,
        isVerticalGrouping: groupCount && isVerticalGroupOrientation,
        getDOMMetaDataCallback: function() {
            return cellsMetaData
        }
    });
    var isGroupedAllDayPanel = (0, _base.calculateIsGroupedAllDayPanel)(appointmentsConfig.loadedResources, appointmentsConfig.groupOrientation, appointmentsConfig.showAllDayPanel);
    var rowCount = viewDataProvider.getRowCount({
        intervalCount: appointmentsConfig.intervalCount,
        currentDate: appointmentsConfig.currentDate,
        viewType: appointmentsConfig.viewType,
        hoursInterval: appointmentsConfig.hoursInterval,
        startDayHour: appointmentsConfig.startDayHour,
        endDayHour: appointmentsConfig.endDayHour
    });
    var allDayHeight = (0, _m_position_helper.getAllDayHeight)(appointmentsConfig.showAllDayPanel, appointmentsConfig.isVerticalGroupOrientation, cellsMetaData);
    var endViewDate = viewDataProvider.getLastCellEndDate();
    var visibleDayDuration = viewDataProvider.getVisibleDayDuration(appointmentsConfig.startDayHour, appointmentsConfig.endDayHour, appointmentsConfig.hoursInterval);
    var _viewDataProvider$get = viewDataProvider.getViewOptions(),
        leftVirtualCellCount = _viewDataProvider$get.startCellIndex,
        topVirtualRowCount = _viewDataProvider$get.startRowIndex;
    var cellDuration = (0, _base.getCellDuration)(appointmentsConfig.viewType, appointmentsConfig.startDayHour, appointmentsConfig.endDayHour, appointmentsConfig.hoursInterval);
    var appointmentRenderingStrategyName = (0, _utils2.getAppointmentRenderingStrategyName)(appointmentsConfig.viewType);
    return _extends({}, appointmentsConfig, {
        appointmentRenderingStrategyName: appointmentRenderingStrategyName,
        loadedResources: appointmentsConfig.loadedResources,
        dataAccessors: dataAccessors,
        timeZoneCalculator: timeZoneCalculator,
        viewDataProvider: viewDataProvider,
        positionHelper: positionHelper,
        isGroupedAllDayPanel: isGroupedAllDayPanel,
        rowCount: rowCount,
        cellWidth: (0, _m_position_helper.getCellWidth)(cellsMetaData),
        cellHeight: (0, _m_position_helper.getCellHeight)(cellsMetaData),
        allDayHeight: allDayHeight,
        isGroupedByDate: groupedByDate,
        endViewDate: endViewDate,
        visibleDayDuration: visibleDayDuration,
        intervalDuration: cellDuration,
        allDayIntervalDuration: toMs("day"),
        leftVirtualCellCount: leftVirtualCellCount,
        topVirtualCellCount: topVirtualRowCount,
        cellDuration: cellDuration,
        resizableStep: positionHelper.getResizableStep(),
        DOMMetaData: cellsMetaData
    })
};
exports.getAppointmentsModel = getAppointmentsModel;
