import { DEFAULT_PARENT_ID } from "../../../../utils/constant.js";
import { ensureParentIdInitialized, isCommonMeasureEncoding } from "./utils.js";
import { DEFAULT_DUAL_CHART_TYPE, isDualAxisChartType } from "../../../../utils/chatType.js";
const buildMeasuresForDualAxis = (advancedVSeed)=>{
    const { measures = [] } = advancedVSeed;
    const measuresByView = {};
    const parentIds = [];
    for(let index = 0; index < measures.length; index++){
        const item = measures[index];
        const encoding = item.encoding;
        const parentId = item.parentId || DEFAULT_PARENT_ID;
        const isPrimaryYAxis = 'primaryYAxis' === encoding;
        const isSecondaryYAxis = 'secondaryYAxis' === encoding;
        const isOtherEncoding = item.encoding && isCommonMeasureEncoding(encoding);
        ensureParentIdInitialized(parentId, measuresByView, parentIds);
        if (isPrimaryYAxis) {
            measuresByView[parentId].push(item);
            if (!isDualAxisChartType(item.chartType)) item.chartType = DEFAULT_DUAL_CHART_TYPE.primary;
        } else if (isSecondaryYAxis) {
            measuresByView[parentId].push(item);
            if (!isDualAxisChartType(item.chartType)) item.chartType = DEFAULT_DUAL_CHART_TYPE.secondary;
        } else if (!isOtherEncoding) {
            const primaryCount = measuresByView[parentId].filter((m)=>'primaryYAxis' === m.encoding).length;
            item.encoding = 0 === primaryCount ? 'primaryYAxis' : 'secondaryYAxis';
            if (!isDualAxisChartType(item.chartType)) item.chartType = 'primaryYAxis' === item.encoding ? DEFAULT_DUAL_CHART_TYPE.primary : DEFAULT_DUAL_CHART_TYPE.secondary;
            measuresByView[parentId].push(item);
        }
    }
    advancedVSeed.reshapeMeasures = parentIds.map((pid)=>measuresByView[pid]).filter((m)=>m.length > 0);
    return advancedVSeed;
};
export { buildMeasuresForDualAxis };

//# sourceMappingURL=buildMeasuresForDualAxis.js.map