"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPieChartEchartsConfig = void 0;
const pieChartStyles_1 = require("../../../../../../visualizations/helpers/styles/pieChartStyles");
const tooltipStyles_1 = require("../../../../../../visualizations/helpers/styles/tooltipStyles");
const getCommonEChartsConfig_1 = require("../../shared/getCommonEChartsConfig");
/**
 * Generates pie chart echarts config for server-side rendering
 */
const getPieChartEchartsConfig = (queryTool, rows) => {
    const { dimensions, metrics } = queryTool.queryConfig;
    const { chartConfig } = queryTool;
    const groupField = dimensions[0];
    const metricField = chartConfig?.yAxisMetrics?.[0] || metrics[0];
    // Transform data for pie chart
    const data = rows.map((row) => ({
        name: String(row[groupField]),
        value: row[metricField],
    }));
    return {
        ...(0, getCommonEChartsConfig_1.getCommonEChartsConfig)({
            title: queryTool.title,
            showLegend: false,
            chartData: rows,
        }),
        tooltip: {
            show: true,
            trigger: 'item',
            ...(0, tooltipStyles_1.getTooltipStyle)({ appendToBody: false }),
        },
        series: [
            {
                type: 'pie',
                data,
                label: {
                    formatter: '{b}: {c} ({d}%)',
                    ...(0, pieChartStyles_1.getPieExternalLabelStyle)(),
                },
                labelLine: (0, pieChartStyles_1.getPieLabelLineStyle)(),
            },
        ],
    };
};
exports.getPieChartEchartsConfig = getPieChartEchartsConfig;
//# sourceMappingURL=pie.js.map