/**
 * DevExtreme (cjs/exporter/exceljs/export_data_grid.js)
 * Version: 22.2.7 (build 23185-0311)
 * Build date: Tue Jul 04 2023
 *
 * Copyright (c) 2012 - 2023 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
exports.exportDataGrid = exportDataGrid;
var _type = require("../../core/utils/type");
var _export = require("./export");
var _export_merged_ranges_manager = require("./export_merged_ranges_manager");
var DataGridHelpers = function() {
    function DataGridHelpers(component, dataProvider, worksheet, options) {
        this.component = component;
        this.dataProvider = dataProvider;
        this.worksheet = worksheet;
        this.mergedRangesManager = new _export_merged_ranges_manager.MergedRangesManager(dataProvider, worksheet);
        this.topLeftCell = options.topLeftCell;
        this.customizeCell = options.customizeCell;
        this.autoFilterEnabled = options.autoFilterEnabled
    }
    var _proto = DataGridHelpers.prototype;
    _proto._getFirstColumnIndex = function() {
        return this.topLeftCell.column
    };
    _proto._getFieldHeaderRowsCount = function() {
        return 0
    };
    _proto._trySetAutoFilter = function(cellRange) {
        if (this.autoFilterEnabled) {
            if (!(0, _type.isDefined)(this.worksheet.autoFilter) && this.dataProvider.getRowsCount() > 0) {
                var dataRange = {
                    from: {
                        row: cellRange.from.row + this.dataProvider.getHeaderRowCount() - 1,
                        column: cellRange.from.column
                    },
                    to: cellRange.to
                };
                this.worksheet.autoFilter = dataRange
            }
        }
    };
    _proto._trySetFont = function(excelCell, bold) {
        if ((0, _type.isDefined)(bold)) {
            excelCell.font = excelCell.font || {};
            excelCell.font.bold = bold
        }
    };
    _proto._getWorksheetFrozenState = function(cellRange) {
        return {
            state: "frozen",
            ySplit: cellRange.from.row + this.dataProvider.getFrozenArea().y - 1
        }
    };
    _proto._trySetOutlineLevel = function(row, rowIndex) {
        if (rowIndex >= this.dataProvider.getHeaderRowCount()) {
            row.outlineLevel = this.dataProvider.getGroupLevel(rowIndex)
        }
    };
    _proto._isFrozenZone = function(dataProvider) {
        return dataProvider.getHeaderRowCount() > 0
    };
    _proto._isHeaderCell = function(rowIndex) {
        return rowIndex < this.dataProvider.getHeaderRowCount()
    };
    _proto._isInfoCell = function() {
        return false
    };
    _proto._allowToMergeRange = function() {
        return true
    };
    _proto._getAllFieldHeaders = function() {
        return []
    };
    _proto._customizeCell = function(excelCell, gridCell) {
        if ((0, _type.isFunction)(this.customizeCell)) {
            this.customizeCell({
                excelCell: excelCell,
                gridCell: gridCell
            })
        }
    };
    _proto._exportFieldHeaders = function() {};
    _proto._exportAllFieldHeaders = function() {};
    _proto._isRowFieldHeadersRow = function() {};
    return DataGridHelpers
}();

function exportDataGrid(options) {
    return _export.Export.export(_getFullOptions(options), DataGridHelpers, _getLoadPanelTargetElement, _getLoadPanelContainer)
}

function _getFullOptions(options) {
    if (!((0, _type.isDefined)(options) && (0, _type.isObject)(options))) {
        throw Error('The "exportDataGrid" method requires a configuration object.')
    }
    if (!((0, _type.isDefined)(options.component) && (0, _type.isObject)(options.component) && "dxDataGrid" === options.component.NAME)) {
        throw Error('The "component" field must contain a DataGrid instance.')
    }
    if (!(0, _type.isDefined)(options.selectedRowsOnly)) {
        options.selectedRowsOnly = false
    }
    if (!(0, _type.isDefined)(options.autoFilterEnabled)) {
        options.autoFilterEnabled = false
    }
    return _export.Export.getFullOptions(options)
}

function _getLoadPanelTargetElement(component) {
    return component.getView("rowsView").element()
}

function _getLoadPanelContainer(component) {
    return component.getView("rowsView").element().parent()
}
