import { ChartType, getHiddenTableFields, } from '../types/savedCharts';
const getTablePivotConfig = (tableChartConfig, pivotConfig, tableConfig) => pivotConfig && pivotConfig.columns.length > 0
    ? {
        pivotDimensions: pivotConfig.columns,
        metricsAsRows: tableChartConfig.config?.metricsAsRows ?? false,
        hiddenMetricFieldIds: 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,
    };
};
export const getPivotConfig = (savedChart) => {
    switch (savedChart.chartConfig.type) {
        case ChartType.TABLE:
            return getTablePivotConfig(savedChart.chartConfig, savedChart.pivotConfig, savedChart.tableConfig);
        case ChartType.CARTESIAN:
            return getCartesianPivotConfig(savedChart.pivotConfig);
        default:
            return undefined;
    }
};
export const getDownloadPivotConfig = (savedChart, exportPivotedData = true) => {
    switch (savedChart.chartConfig.type) {
        case ChartType.TABLE:
            return getPivotConfig(savedChart);
        case ChartType.CARTESIAN:
            return exportPivotedData ? getPivotConfig(savedChart) : undefined;
        default:
            return undefined;
    }
};
export const getDownloadPivotOptions = (savedChart, exportPivotedData = true) => ({
    pivotConfig: getDownloadPivotConfig(savedChart, exportPivotedData),
    exportPivotedData: savedChart.chartConfig.type === ChartType.CARTESIAN
        ? exportPivotedData
        : true,
});
//# sourceMappingURL=pivotConfig.js.map