import { unique } from "remeda";
import { FoldXMeasureId, FoldYMeasureId, MeasureId } from "../../../../../dataReshape/index.js";
const defaultEncodingForScatter = (advancedVSeed)=>{
    const { measures = [], dimensions = [] } = advancedVSeed;
    const encoding = {};
    generateDefaultDimensionEncoding(dimensions, encoding);
    generateDefaultMeasureEncoding(measures, encoding);
    return {
        ...advancedVSeed,
        encoding
    };
};
const encodingForScatter = (advancedVSeed)=>{
    const { measures = [], dimensions = [] } = advancedVSeed;
    const hasDimensionEncoding = dimensions.some((item)=>item.encoding);
    const hasMeasureEncoding = measures.some((item)=>item.encoding);
    const encoding = {};
    if (hasDimensionEncoding) generateDimensionEncoding(dimensions, encoding);
    else generateDefaultDimensionEncoding(dimensions, encoding);
    if (hasMeasureEncoding) generateMeasureEncoding(measures, encoding);
    else generateDefaultMeasureEncoding(measures, encoding);
    return {
        ...advancedVSeed,
        encoding
    };
};
const generateDefaultDimensionEncoding = (dimensions, encoding)=>{
    const dimensionsWithoutMeasureId = dimensions.filter((item)=>item.id !== MeasureId);
    const uniqueDimIds = unique(dimensionsWithoutMeasureId.map((d)=>d.id));
    encoding.detail = encoding.color;
    encoding.tooltip = uniqueDimIds.filter((d)=>![
            MeasureId,
            FoldYMeasureId,
            FoldXMeasureId
        ].includes(d));
    encoding.label = [];
    encoding.row = [];
    encoding.column = [];
};
const generateDimensionEncoding = (dimensions, encoding)=>{
    encoding.color = unique(dimensions.filter((item)=>'color' === item.encoding).map((item)=>item.id));
    encoding.detail = unique(dimensions.filter((item)=>'detail' === item.encoding).map((item)=>item.id));
    if (0 === encoding.detail.length) encoding.detail = [
        MeasureId
    ];
    encoding.tooltip = unique(dimensions.map((item)=>item.id));
    encoding.tooltip = encoding.tooltip.filter((d)=>![
            MeasureId,
            FoldYMeasureId,
            FoldXMeasureId
        ].includes(d));
    encoding.label = unique(dimensions.filter((item)=>'label' === item.encoding).map((item)=>item.id));
    encoding.label = encoding.label.filter((d)=>d !== MeasureId);
};
const generateDefaultMeasureEncoding = (measures, encoding)=>{
    encoding.y = unique(measures.filter((item)=>'xAxis' === item.encoding || 'yAxis' === item.encoding || !item.encoding).map((item)=>item.id));
};
const generateMeasureEncoding = (measures, encoding)=>{
    encoding.y = unique(measures.filter((item)=>'xAxis' === item.encoding || 'yAxis' === item.encoding || !item.encoding).map((item)=>item.id));
    const color = unique(measures.filter((item)=>'color' === item.encoding).map((item)=>item.id));
    if (color.length > 0) encoding.color = [
        color[0]
    ];
    encoding.size = unique(measures.filter((item)=>'size' === item.encoding).map((item)=>item.id));
    const label = unique(measures.filter((item)=>'label' === item.encoding).map((item)=>item.id));
    encoding.label = unique([
        ...encoding.label || [],
        ...label
    ]);
    const tooltip = unique(measures.filter((item)=>'tooltip' === item.encoding).map((item)=>item.id));
    encoding.tooltip = unique([
        ...encoding.tooltip || [],
        ...label,
        ...tooltip,
        ...color,
        ...encoding.size
    ]);
};
export { defaultEncodingForScatter, encodingForScatter };

//# sourceMappingURL=scatter.js.map