"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRunQueryChartConfig = void 0;
const savedCharts_1 = require("../../../../../types/savedCharts");
const canRenderAsChart_1 = require("../shared/canRenderAsChart");
const bar_1 = require("./viz/bar");
const funnel_1 = require("./viz/funnel");
const horizontalBar_1 = require("./viz/horizontalBar");
const line_1 = require("./viz/line");
const pie_1 = require("./viz/pie");
const scatter_1 = require("./viz/scatter");
/**
 * Converts runQuery tool result to echarts config
 * This is the main function used for chart type switching
 */
const getRunQueryChartConfig = ({ queryTool, metricQuery, fieldsMap, overrideChartType, }) => {
    const chartType = overrideChartType ?? queryTool.chartConfig?.defaultVizType ?? 'table';
    if (!(0, canRenderAsChart_1.canRenderAsChart)(chartType, metricQuery)) {
        // Fallback to table if chart type is not valid
        return { type: savedCharts_1.ChartType.TABLE };
    }
    const { chartConfig } = queryTool;
    const metadata = {
        title: queryTool.title,
        description: queryTool.description,
    };
    switch (chartType) {
        case 'table':
            return { type: savedCharts_1.ChartType.TABLE };
        case 'bar':
            return (0, bar_1.getBarChartConfig)({
                queryTool,
                metricQuery,
                fieldsMap,
                chartConfig,
                metadata,
            });
        case 'horizontal':
            return (0, horizontalBar_1.getHorizontalBarChartConfig)({
                queryTool,
                metricQuery,
                fieldsMap,
                chartConfig,
                metadata,
            });
        case 'line':
            return (0, line_1.getLineChartConfig)({
                queryTool,
                metricQuery,
                fieldsMap,
                chartConfig,
                metadata,
            });
        case 'scatter':
            return (0, scatter_1.getScatterChartConfig)({
                queryTool,
                metricQuery,
                fieldsMap,
                chartConfig,
                metadata,
            });
        case 'pie':
            return (0, pie_1.getPieChartConfig)({
                queryTool,
                metricQuery,
            });
        case 'funnel':
            return (0, funnel_1.getFunnelChartConfig)({
                queryTool,
                metricQuery,
            });
        default:
            throw new Error(`Unknown chart type: ${chartType}`);
    }
};
exports.getRunQueryChartConfig = getRunQueryChartConfig;
//# sourceMappingURL=getRunQueryChartConfig.js.map