import { uniqueBy } from "remeda";
import { FoldMeasureValue, dataReshapeByEncoding } from "../../../../../dataReshape/index.js";
import { getColorMeasureId } from "../../../../spec/chart/pipes/index.js";
import { DEFAULT_PARENT_ID } from "../../../../utils/constant.js";
const pivotReshapeWithEncoding = (advancedVSeed, context)=>{
    const result = {
        ...advancedVSeed
    };
    const { vseed } = context;
    const { dataset } = vseed;
    const { encoding } = advancedVSeed;
    const reshapeMeasures = advancedVSeed.reshapeMeasures ?? [];
    const dimensions = advancedVSeed.reshapeDimensions ?? advancedVSeed.dimensions ?? [];
    const allMeasuresIds = reshapeMeasures.flatMap((measureGroup)=>measureGroup.map((m)=>m.id));
    const datasets = [];
    const datasetReshapeInfo = [];
    reshapeMeasures.forEach((measures, index)=>{
        if (!measures) return;
        const groupId = measures[0].parentId ?? DEFAULT_PARENT_ID;
        const { dataset: newSubDataset, foldInfo, unfoldInfo } = dataReshapeByEncoding(dataset, uniqueBy(dimensions, (item)=>item.id), uniqueBy(measures, (item)=>item.id), encoding, {
            colorItemAsId: false,
            foldMeasureValue: `${FoldMeasureValue}${groupId}`,
            colorMeasureId: getColorMeasureId(advancedVSeed, vseed),
            omitIds: allMeasuresIds
        });
        const reshapeInfo = {
            id: `${groupId}`,
            index,
            foldInfo,
            unfoldInfo
        };
        datasets.push(newSubDataset);
        datasetReshapeInfo.push(reshapeInfo);
    });
    return {
        ...result,
        dataset: datasets,
        datasetReshapeInfo: datasetReshapeInfo
    };
};
export { pivotReshapeWithEncoding };

//# sourceMappingURL=pivotReshapeWithEncoding.js.map