import { merge } from "@visactor/vutils";
import { pick } from "remeda";
import { BinEndMeasureId, BinStartMeasureId } from "../../../../../dataReshape/index.js";
import { replaceNullToUndefined } from "../../../../utils/index.js";
const histogramConfig = (advancedVSeed, context)=>{
    const { vseed } = context;
    const { chartType } = vseed;
    const result = {
        ...advancedVSeed
    };
    const hasColorEncoding = (advancedVSeed?.dimensions || []).find((field)=>field?.encoding === 'color');
    const pickedConfig = pick(vseed, [
        'backgroundColor',
        'color',
        'label',
        'legend',
        'tooltip',
        'xAxis',
        'yAxis',
        'crosshairRect',
        'binCount',
        'binStep',
        'binValueType',
        'brush',
        'dimensionLinkage'
    ]);
    let config = replaceNullToUndefined(pickedConfig);
    if (pickedConfig?.binValueType === 'percentage') config = merge({}, {
        yAxis: {
            autoFomat: false,
            numFormat: {
                type: 'percent',
                fractionDigits: 1
            }
        },
        label: {
            autoFormat: false,
            numFormat: {
                type: 'percent',
                fractionDigits: 1
            }
        }
    }, config);
    if (!hasColorEncoding && !config?.legend?.enable) config = {
        ...config,
        legend: {
            ...config?.legend,
            enable: false
        }
    };
    result.config = {
        ...result.config,
        [chartType]: {
            ...config
        }
    };
    return result;
};
const histogramXAxisConfig = (advancedVSeed, context)=>{
    const { vseed } = context;
    const { chartType } = vseed;
    const result = {
        ...advancedVSeed
    };
    const { dataset = [] } = advancedVSeed;
    const flattenDatasert = dataset.flat();
    const minValue = Math.min(...flattenDatasert.map((v)=>+v[BinStartMeasureId]));
    const maxValue = Math.max(...flattenDatasert.map((v)=>+v[BinEndMeasureId]));
    const chartConfig = result.config?.[chartType];
    result.config = {
        ...result.config || {},
        [chartType]: {
            ...chartConfig,
            xAxis: {
                min: Number.isNaN(minValue) ? void 0 : minValue,
                max: Number.isNaN(maxValue) ? void 0 : maxValue,
                ...chartConfig?.xAxis || {}
            }
        }
    };
    return result;
};
export { histogramConfig, histogramXAxisConfig };

//# sourceMappingURL=histogram.js.map