"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDownloadPivotOptions = exports.getDownloadPivotConfig = exports.getPivotConfig = void 0;
const savedCharts_1 = require("../types/savedCharts");
const getTablePivotConfig = (tableChartConfig, pivotConfig, tableConfig) => pivotConfig && pivotConfig.columns.length > 0
    ? {
        pivotDimensions: pivotConfig.columns,
        metricsAsRows: tableChartConfig.config?.metricsAsRows ?? false,
        hiddenMetricFieldIds: (0, savedCharts_1.getHiddenTableFields)(tableChartConfig),
        columnOrder: tableConfig.columnOrder,
        rowTotals: tableChartConfig.config?.showRowCalculation ?? false,
        columnTotals: tableChartConfig.config?.showColumnCalculation ?? false,
    }
    : undefined;
const getCartesianPivotConfig = (pivotConfig) => {
    if (!pivotConfig || pivotConfig.columns.length === 0) {
        return undefined;
    }
    return {
        pivotDimensions: pivotConfig.columns,
        metricsAsRows: false,
    };
};
const getPivotConfig = (savedChart) => {
    switch (savedChart.chartConfig.type) {
        case savedCharts_1.ChartType.TABLE:
            return getTablePivotConfig(savedChart.chartConfig, savedChart.pivotConfig, savedChart.tableConfig);
        case savedCharts_1.ChartType.CARTESIAN:
            return getCartesianPivotConfig(savedChart.pivotConfig);
        default:
            return undefined;
    }
};
exports.getPivotConfig = getPivotConfig;
const getDownloadPivotConfig = (savedChart, exportPivotedData = true) => {
    switch (savedChart.chartConfig.type) {
        case savedCharts_1.ChartType.TABLE:
            return (0, exports.getPivotConfig)(savedChart);
        case savedCharts_1.ChartType.CARTESIAN:
            return exportPivotedData ? (0, exports.getPivotConfig)(savedChart) : undefined;
        default:
            return undefined;
    }
};
exports.getDownloadPivotConfig = getDownloadPivotConfig;
const getDownloadPivotOptions = (savedChart, exportPivotedData = true) => ({
    pivotConfig: (0, exports.getDownloadPivotConfig)(savedChart, exportPivotedData),
    exportPivotedData: savedChart.chartConfig.type === savedCharts_1.ChartType.CARTESIAN
        ? exportPivotedData
        : true,
});
exports.getDownloadPivotOptions = getDownloadPivotOptions;
//# sourceMappingURL=pivotConfig.js.map