import { AXIS_LABEL_SPACE, LINEAR_AXIS_INNER_OFFSET_TOP } from "../../../../utils/constant.js";
import { createNumFormatter } from "../../../../utils/index.js";
import { isEmpty, isNullish } from "remeda";
import { createLinearFormat } from "./format/linearFormat.js";
import { defaultTitleText } from "./title/defaultTitleText.js";
const yLinearSecondary = (spec, context)=>{
    const result = {
        ...spec
    };
    const { advancedVSeed, vseed } = context;
    const { chartType } = vseed;
    const { datasetReshapeInfo, measures, dimensions, encoding } = advancedVSeed;
    const { index, id: reshapeInfoId, foldInfoList } = datasetReshapeInfo[0];
    const secondaryYAxis = advancedVSeed.config?.[chartType]?.secondaryYAxis;
    const yAxisConfig = Array.isArray(secondaryYAxis) ? secondaryYAxis[index] || secondaryYAxis[0] : secondaryYAxis;
    const alignTicks = advancedVSeed.config?.[chartType]?.alignTicks;
    const alignTicksConfig = Array.isArray(alignTicks) ? alignTicks[index] || alignTicks[0] : alignTicks;
    if (isNullish(foldInfoList?.[1])) return result;
    const isEmptySecondary = isEmpty(foldInfoList?.[1].foldMap);
    const onlySecondary = isEmpty(foldInfoList?.[0].foldMap) && !isEmptySecondary;
    const sync = {
        axisId: `${reshapeInfoId}-primary-axis`,
        zeroAlign: true
    };
    const id = `${reshapeInfoId}-secondary-axis`;
    const seriesIds = [
        `${reshapeInfoId}-primary-series`,
        `${reshapeInfoId}-secondary-series`
    ];
    const seriesId = alignTicksConfig ? seriesIds : seriesIds[1];
    if (!result.axes) result.axes = [];
    const { visible = true, label, tick, title, grid, line, zero, nice, inverse, max, min, log, logBase = 10, numFormat = {}, autoFormat } = yAxisConfig;
    const formatter = createNumFormatter(numFormat);
    const linearAxis = {
        visible: isEmptySecondary ? false : visible,
        id,
        seriesId,
        sync,
        type: log ? 'log' : 'linear',
        base: logBase,
        orient: 'right',
        nice,
        zero: log ? false : zero,
        inverse,
        max,
        min,
        label: {
            space: AXIS_LABEL_SPACE,
            visible: label?.visible,
            formatMethod: (value)=>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.y),
            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: onlySecondary ? true : grid?.visible,
            style: {
                lineWidth: grid?.gridWidth,
                stroke: grid?.gridColor,
                lineDash: grid?.gridLineDash
            }
        },
        domainLine: {
            visible: line?.visible,
            style: {
                lineWidth: line?.lineWidth,
                stroke: line?.lineColor
            }
        },
        innerOffset: {
            top: LINEAR_AXIS_INNER_OFFSET_TOP
        }
    };
    result.axes = [
        ...result.axes,
        linearAxis
    ];
    return result;
};
export { yLinearSecondary };

//# sourceMappingURL=yLinearSecondary.js.map