import { AXIS_LABEL_SPACE, LINEAR_AXIS_INNER_OFFSET_TOP, createNumFormatter, isAreaPercent, isBarPercent, isColumnPercent, isPivotChart } from "../../../../utils/index.js";
import { createLinearFormat, createLinearPercentFormat } from "./format/linearFormat.js";
import { defaultTitleText } from "./title/defaultTitleText.js";
const xLinear = (spec, context)=>{
    const result = {
        ...spec
    };
    const { advancedVSeed, vseed } = context;
    const { encoding, dimensions, measures } = advancedVSeed;
    const { chartType } = vseed;
    const config = advancedVSeed.config?.[chartType]?.xAxis;
    if (!result.axes) result.axes = [];
    const isPivot = isPivotChart(vseed);
    const { visible = true, label, tick, title, grid, line, zero, nice, inverse, max, min, log, logBase = 10, autoFormat, numFormat = {} } = config;
    const formatter = createNumFormatter(numFormat);
    const percentFormatter = createNumFormatter({
        type: 'percent'
    });
    const linearAxis = {
        ...isPivot ? {
            range: {
                min,
                max
            }
        } : {
            min,
            max
        },
        visible,
        type: log ? 'log' : 'linear',
        base: logBase,
        orient: 'bottom',
        nice,
        zero: log ? false : zero,
        inverse,
        label: {
            space: AXIS_LABEL_SPACE,
            visible: label?.visible,
            formatMethod: (value)=>{
                if (isBarPercent(vseed) || isColumnPercent(vseed) || isAreaPercent(vseed)) return createLinearPercentFormat(value, autoFormat, numFormat, formatter, percentFormatter);
                return createLinearFormat(value, autoFormat, numFormat, formatter);
            },
            style: {
                fill: label?.labelColor,
                angle: label?.labelAngle,
                fontSize: label?.labelFontSize,
                fontWeight: label?.labelFontWeight
            }
        },
        title: {
            visible: title?.visible,
            text: title?.titleText || defaultTitleText(measures, dimensions, encoding.x),
            style: {
                fill: title?.titleColor,
                fontSize: title?.titleFontSize,
                fontWeight: title?.titleFontWeight
            }
        },
        tick: {
            visible: tick?.visible,
            tickSize: tick?.tickSize,
            inside: tick?.tickInside,
            style: {
                stroke: tick?.tickColor
            }
        },
        grid: {
            visible: grid?.visible,
            style: {
                lineWidth: grid?.gridWidth,
                stroke: grid?.gridColor,
                lineDash: grid?.gridLineDash
            }
        },
        domainLine: {
            visible: line?.visible,
            style: {
                lineWidth: line?.lineWidth,
                stroke: line?.lineColor
            }
        },
        innerOffset: {
            right: LINEAR_AXIS_INNER_OFFSET_TOP
        }
    };
    result.axes = [
        ...result.axes,
        linearAxis
    ];
    return result;
};
export { xLinear };

//# sourceMappingURL=xLinear.js.map