"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFunnelChartEchartsConfig = void 0;
const item_1 = require("../../../../../../utils/item");
const getCommonEChartsConfig_1 = require("../../shared/getCommonEChartsConfig");
/**
 * Generates funnel chart echarts config for server-side rendering
 */
const getFunnelChartEchartsConfig = (queryTool, rows, fieldsMap) => {
    const { dimensions, metrics } = queryTool.queryConfig;
    const { chartConfig } = queryTool;
    const metricField = chartConfig?.yAxisMetrics?.[0] || metrics[0];
    // Stages come from rows (dimension + metric) or, for single-row results
    // without dimensions, from the metric columns themselves
    const data = dimensions.length === 0
        ? metrics.map((metric) => {
            const item = fieldsMap[metric];
            return {
                name: item ? (0, item_1.getItemLabelWithoutTableName)(item) : metric,
                value: rows[0][metric],
            };
        })
        : rows.map((row) => ({
            name: String(row[dimensions[0]]),
            value: row[metricField],
        }));
    return {
        ...(0, getCommonEChartsConfig_1.getCommonEChartsConfig)({
            title: queryTool.title,
            showLegend: false,
            chartData: rows,
        }),
        tooltip: {
            show: true,
            trigger: 'item',
        },
        legend: {
            show: true,
            orient: 'horizontal',
            bottom: 10,
        },
        series: [
            {
                type: 'funnel',
                data,
                label: {
                    position: 'inside',
                },
                sort: 'descending',
            },
        ],
    };
};
exports.getFunnelChartEchartsConfig = getFunnelChartEchartsConfig;
//# sourceMappingURL=funnel.js.map