import { createNumFormatter, isAreaPercent, isBarPercent, isColumnPercent, isPivotChart } from "../../../../utils/index.js";
import { createLinearFormat, createLinearPercentFormat } from "./format/linearFormat.js";
import { defaultTitleText } from "./title/defaultTitleText.js";
import { linearAxisStyle } from "./linearAxisStyle.js";
import { BinEndMeasureId, BinStartMeasureId } from "../../../../../dataReshape/constant.js";
import { unique } from "remeda";
const histogramXLinear = (spec, context)=>{
    const result = {
        ...spec
    };
    const { advancedVSeed, vseed } = context;
    const { encoding, dimensions = [], measures = [], dataset } = advancedVSeed;
    const { chartType } = vseed;
    const config = advancedVSeed.config?.[chartType]?.xAxis ?? {};
    if (!result.axes) result.axes = [];
    const isPivot = isPivotChart(vseed);
    const { autoFormat, numFormat = {} } = config;
    const formatter = createNumFormatter(numFormat);
    const percentFormatter = createNumFormatter({
        type: 'percent'
    });
    const formatMethod = (value)=>{
        if (isBarPercent(vseed) || isColumnPercent(vseed) || isAreaPercent(vseed)) return createLinearPercentFormat(value, autoFormat, numFormat, formatter, percentFormatter);
        return createLinearFormat(value, autoFormat, numFormat, formatter);
    };
    const titleText = config.title?.titleText || defaultTitleText(measures, dimensions, encoding.x);
    const linearAxis = linearAxisStyle({
        ...config,
        orient: 'bottom',
        formatMethod,
        titleText,
        isPivot
    });
    linearAxis.tick.tickMode = ()=>{
        const binValues = [];
        dataset.forEach((entry)=>{
            binValues.push(entry[BinStartMeasureId]);
            binValues.push(entry[BinEndMeasureId]);
        });
        return unique(binValues);
    };
    result.axes = [
        ...result.axes,
        linearAxis
    ];
    return result;
};
export { histogramXLinear };

//# sourceMappingURL=histogramXLinear.js.map