import { uniqueBy } from "remeda";
import { FoldXMeasureId, FoldXMeasureValue, FoldYMeasureId, FoldYMeasureValue, dataReshapeByEncoding } from "../../../../../dataReshape/index.js";
import { getColorMeasureId } from "../../../../spec/chart/pipes/index.js";
const reshapeWithScatterEncoding = (advancedVSeed, context)=>{
    const result = {
        ...advancedVSeed
    };
    const { vseed } = context;
    const { dataset } = vseed;
    const { encoding, chartType, reshapeMeasures } = advancedVSeed;
    const dimensions = advancedVSeed.reshapeDimensions ?? advancedVSeed.dimensions ?? [];
    const measures = reshapeMeasures?.[0] ?? [];
    const foldInfoList = [];
    const unfoldInfoList = [];
    const sizeEncodingIds = encoding?.size ?? [];
    const datasets = [];
    const xMeasures = measures.filter((m)=>'xAxis' === m.encoding);
    const yMeasures = measures.filter((m)=>'yAxis' === m.encoding);
    const xResult = dataReshapeByEncoding(dataset, uniqueBy(dimensions, (d)=>d.id), uniqueBy(xMeasures, (d)=>d.id), encoding, {
        foldMeasureValue: FoldXMeasureValue,
        foldMeasureId: FoldXMeasureId,
        colorItemAsId: true,
        colorMeasureId: getColorMeasureId(advancedVSeed, vseed),
        omitIds: xMeasures.map((m)=>m.id).filter((id)=>!sizeEncodingIds.includes(id))
    });
    datasets.push(xResult.dataset);
    foldInfoList.push(xResult.foldInfo);
    unfoldInfoList.push(xResult.unfoldInfo);
    const yResult = dataReshapeByEncoding(datasets[0], uniqueBy(dimensions, (d)=>d.id), uniqueBy(yMeasures, (d)=>d.id), encoding, {
        foldMeasureValue: FoldYMeasureValue,
        foldMeasureId: FoldYMeasureId,
        colorItemAsId: true,
        colorMeasureId: getColorMeasureId(advancedVSeed, vseed),
        omitIds: yMeasures.map((m)=>m.id).filter((id)=>!sizeEncodingIds.includes(id))
    });
    datasets[0] = yResult.dataset;
    foldInfoList.push(yResult.foldInfo);
    unfoldInfoList.push(yResult.unfoldInfo);
    const unfoldInfo = {
        ...unfoldInfoList[0],
        colorItems: unfoldInfoList.flatMap((d)=>d.colorItems),
        colorIdMap: unfoldInfoList.reduce((prev, cur)=>({
                ...prev,
                ...cur.colorIdMap
            }), {})
    };
    return {
        ...result,
        dataset: datasets[0],
        datasetReshapeInfo: [
            {
                id: String(chartType),
                index: 0,
                foldInfo: foldInfoList[0],
                foldInfoList: foldInfoList,
                unfoldInfo: unfoldInfo
            }
        ]
    };
};
export { reshapeWithScatterEncoding };

//# sourceMappingURL=reshapeWithScatterEncoding.js.map