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";
const xLinear = (spec, context)=>{
    const result = {
        ...spec
    };
    const { advancedVSeed, vseed } = context;
    const { encoding, dimensions = [], measures = [], datasetReshapeInfo } = advancedVSeed;
    const { chartType } = vseed;
    const config = advancedVSeed.config?.[chartType]?.xAxis ?? {};
    const { foldInfo, foldInfoList } = datasetReshapeInfo[0];
    if (!result.axes) result.axes = [];
    const isPivot = isPivotChart(vseed);
    const xFoldInfo = foldInfoList?.length ? foldInfoList[0] : foldInfo;
    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,
        max: true === config.max ? xFoldInfo.statistics.max : config.max
    });
    result.axes = [
        ...result.axes,
        linearAxis
    ];
    return result;
};
export { xLinear };

//# sourceMappingURL=xLinear.js.map