import { getAxisPointerStyle } from '../../../../../visualizations/helpers/styles/axisStyles';
import { getLegendStyle } from '../../../../../visualizations/helpers/styles/legendStyles';
import { getTooltipStyle } from '../../../../../visualizations/helpers/styles/tooltipStyles';
const FONT_FAMILY = '"Inter", "Noto Sans JP", "Noto Sans CJK JP", sans-serif';
/**
 * Generates common echarts config for all chart types
 */
export const getCommonEChartsConfig = ({ title, showLegend, chartData, xAxisLabel, yAxisLabel, secondaryYAxisLabel, useLinePointer = false, showTooltip = false, }) => {
    const graphicElements = [];
    // Add X-axis label at bottom center
    if (xAxisLabel) {
        graphicElements.push({
            type: 'text',
            left: 'center',
            bottom: 10,
            style: {
                text: xAxisLabel,
                fontSize: 12,
                fontWeight: 500,
                fontFamily: FONT_FAMILY,
            },
        });
    }
    // Add Y-axis label on left side, vertically centered and rotated
    if (yAxisLabel) {
        graphicElements.push({
            type: 'text',
            left: 10,
            top: 'center',
            rotation: Math.PI / 2,
            style: {
                text: yAxisLabel,
                fontSize: 12,
                fontWeight: 500,
                fontFamily: FONT_FAMILY,
            },
        });
    }
    // Add secondary Y-axis label on right side, vertically centered and rotated
    if (secondaryYAxisLabel) {
        graphicElements.push({
            type: 'text',
            right: 10,
            top: 'center',
            rotation: Math.PI / 2,
            style: {
                text: secondaryYAxisLabel,
                fontSize: 12,
                fontWeight: 500,
                fontFamily: FONT_FAMILY,
            },
        });
    }
    const legendBase = getLegendStyle('square');
    return {
        textStyle: {
            fontFamily: FONT_FAMILY,
        },
        ...(title
            ? {
                title: {
                    text: title,
                    left: 'center',
                    top: 10,
                    textStyle: {
                        fontSize: 16,
                        fontWeight: 'bold',
                        fontFamily: FONT_FAMILY,
                    },
                },
            }
            : {}),
        tooltip: {
            show: showTooltip,
            trigger: 'axis',
            ...getTooltipStyle({ appendToBody: false }),
            axisPointer: {
                ...getAxisPointerStyle(useLinePointer),
                label: {
                    show: true,
                    fontWeight: 500,
                    fontSize: 11,
                },
            },
        },
        legend: {
            show: showLegend,
            type: 'scroll',
            orient: 'horizontal',
            top: title ? 40 : 10, // Position below title if exists, otherwise at top
            left: 'center',
            padding: [5, 10],
            ...legendBase,
        },
        grid: {
            containLabel: true, // Ensures labels are within grid bounds to prevent cutoff
            left: '5%', // Increased from 3% to give more space for Y-axis labels
            right: '5%', // Increased from 3% to give more space for labels on right
            // Account for title + legend at top
            top: (() => {
                if (title && showLegend)
                    return 90; // Title + legend both present
                if (title)
                    return 60; // Only title
                if (showLegend)
                    return 50; // Only legend
                return 30; // Neither
            })(),
            bottom: 60, // Fixed bottom spacing for x-axis labels
        },
        animation: false,
        backgroundColor: '#fff',
        dataset: {
            source: chartData,
            dimensions: Object.keys(chartData[0] || {}),
        },
        ...(graphicElements.length > 0 ? { graphic: graphicElements } : {}),
    };
};
//# sourceMappingURL=getCommonEChartsConfig.js.map