/**
 * DevExtreme (esm/exporter.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 {
    fileSaver
} from "./exporter/file_saver";
import {
    imageCreator,
    testFormats,
    getData as getImageData
} from "./exporter/image_creator";
import {
    svgCreator,
    getData as getSvgData
} from "./exporter/svg_creator";
import {
    isFunction as _isFunction,
    isBoolean
} from "./core/utils/type";
import {
    Deferred
} from "./core/utils/deferred";
import {
    getData
} from "./exporter/pdf_creator";

function _export(data, options, getData) {
    if (!data) {
        return (new Deferred).resolve()
    }
    var exportingAction = options.exportingAction;
    var exportedAction = options.exportedAction;
    var fileSavingAction = options.fileSavingAction;
    var eventArgs = {
        fileName: options.fileName,
        format: options.format,
        cancel: false
    };
    if (isBoolean(options.selectedRowsOnly)) {
        eventArgs.selectedRowsOnly = options.selectedRowsOnly
    }
    _isFunction(exportingAction) && exportingAction(eventArgs);
    if (!eventArgs.cancel) {
        return getData(data, options).then(blob => {
            _isFunction(exportedAction) && exportedAction();
            if (_isFunction(fileSavingAction)) {
                eventArgs.data = blob;
                fileSavingAction(eventArgs)
            }
            if (!eventArgs.cancel) {
                var format = "xlsx" === options.format ? "EXCEL" : options.format;
                fileSaver.saveAs(eventArgs.fileName, format, blob)
            }
        })
    }
    return (new Deferred).resolve()
}
export {
    _export as
    export, fileSaver
};
export var image = {
    creator: imageCreator,
    getData: getImageData,
    testFormats: testFormats
};
export var pdf = {
    getData: getData
};
export var svg = {
    creator: svgCreator,
    getData: getSvgData
};
