"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportExportDropdown = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_redux_1 = require("react-redux");
const DropdownButton_1 = tslib_1.__importDefault(require("../../components/DropdownButton"));
const icons_1 = require("../../components/icons");
const Enums_1 = require("../../PredefinedConfig/Common/Enums");
const ExportRedux_1 = require("../../Redux/ActionsReducers/ExportRedux");
const GeneralConstants_1 = require("../../Utilities/Constants/GeneralConstants");
const AdaptableContext_1 = require("../AdaptableContext");
const ReportExportDropdown = (props) => {
    const report = props.data;
    const adaptable = (0, AdaptableContext_1.useAdaptable)();
    const dispatch = (0, react_redux_1.useDispatch)();
    const handleExport = (destination) => {
        dispatch((0, ExportRedux_1.ExportApply)(report, destination));
    };
    const destinationItems = [
        ...adaptable.api.exportApi.getAvailableExportDestinations().map((destination) => ({
            label: destination,
            onClick: () => handleExport(destination),
            disabled: !adaptable.api.exportApi.internalApi.isDestinationEnabled(destination),
        })),
        ...adaptable.api.exportApi.getCustomDestinations().map((destination) => ({
            label: destination.name,
            onClick: () => {
                handleExport(destination.name);
            },
        })),
    ];
    if ((report === null || report === void 0 ? void 0 : report.Name) === GeneralConstants_1.VISUAL_DATA_REPORT) {
        destinationItems.forEach((item) => (item.disabled = item.label === Enums_1.ExportDestination.Excel ? false : true));
    }
    return (React.createElement(DropdownButton_1.default, { "data-name": "export-dropdown", columns: ['label'], tooltip: "Export Report", variant: "text", items: destinationItems },
        React.createElement(icons_1.Icon, { name: "export" })));
};
exports.ReportExportDropdown = ReportExportDropdown;
