import { defaultTitleText } from "./title/defaultTitleText.js";
import { MeasureId } from "../../../../../dataReshape/index.js";
import { isArray, isNil } from "@visactor/vutils";
import { bandAxisStyle } from "./bandAxisStyle.js";
const yBand = (spec, context)=>{
    const result = {
        ...spec
    };
    const { advancedVSeed, vseed } = context;
    const { chartType } = vseed;
    const { measures = [], dimensions = [], encoding, datasetReshapeInfo, pivotAllDatasetReshapeInfo } = advancedVSeed;
    const config = advancedVSeed.config?.[chartType]?.yAxis ?? {};
    if (!result.axes) result.axes = [];
    const { labelAutoLimitLength = 80 } = config;
    const onlyMeasureId = 0 === (encoding.y || []).filter((v)=>v !== MeasureId).length;
    const bandAxis = bandAxisStyle(config);
    bandAxis.type = 'band';
    bandAxis.orient = 'left';
    bandAxis.maxWidth = labelAutoLimitLength + 60;
    if (bandAxis.label) bandAxis.label.containerAlign = 'right';
    bandAxis.paddingInner = [
        0.15,
        0.1
    ];
    bandAxis.paddingOuter = [
        0.075,
        0.1
    ];
    if (isNil(bandAxis.title?.text)) bandAxis.title.text = defaultTitleText(measures, dimensions, encoding.y);
    if (onlyMeasureId && bandAxis.label) {
        const allDatasetReshapeInfo = pivotAllDatasetReshapeInfo || datasetReshapeInfo;
        const colorIdMap = allDatasetReshapeInfo.reduce((prev, cur)=>({
                ...prev,
                ...cur.unfoldInfo.colorIdMap
            }), {});
        bandAxis.label.formatMethod = (text)=>isArray(text) ? text : colorIdMap[String(text)]?.alias ?? text;
    }
    result.axes = [
        ...result.axes,
        bandAxis
    ];
    return result;
};
export { yBand };

//# sourceMappingURL=yBand.js.map