import { unique } from "remeda";
import { MeasureId } from "../../../../../dataReshape/index.js";
import { hasMultipleMeasureInSingleView } from "../../../../utils/index.js";
import { addColorToEncoding } from "./color/index.js";
import { addDefaultColorEncoding } from "./color/addColorToEncoding.js";
const defaultEncodingForRaceColumn = (advancedVSeed)=>{
    const { measures = [], reshapeMeasures = [], dimensions = [] } = advancedVSeed;
    const encoding = {};
    generateDefaultDimensionEncoding(dimensions, encoding, hasMultipleMeasureInSingleView(reshapeMeasures));
    generateDefaultMeasureEncoding(measures, encoding);
    return {
        ...advancedVSeed,
        encoding
    };
};
const encodingForRaceColumn = (advancedVSeed)=>{
    const { measures = [], reshapeMeasures = [], dimensions = [] } = advancedVSeed;
    const hasDimensionEncoding = dimensions.some((item)=>item.encoding);
    const hasMeasureEncoding = measures.some((item)=>item.encoding);
    const encoding = {};
    const hasMulti = hasMultipleMeasureInSingleView(reshapeMeasures);
    if (hasDimensionEncoding) generateDimensionEncoding(dimensions, encoding, hasMulti);
    else generateDefaultDimensionEncoding(dimensions, encoding, hasMulti);
    if (hasMeasureEncoding) generateMeasureEncoding(measures, encoding);
    else generateDefaultMeasureEncoding(measures, encoding);
    return {
        ...advancedVSeed,
        encoding
    };
};
const generateDefaultDimensionEncoding = (dimensions, encoding, isMultiMeasure)=>{
    const uniqueDimIds = unique(dimensions.map((d)=>d.id));
    encoding.player = uniqueDimIds.slice(0, 1);
    encoding.x = uniqueDimIds.slice(1, 2);
    addDefaultColorEncoding(uniqueDimIds, encoding, isMultiMeasure);
    encoding.detail = encoding.color;
    encoding.tooltip = uniqueDimIds.filter((d)=>d !== MeasureId);
    encoding.label = [];
    encoding.row = [];
    encoding.column = [];
};
const generateDimensionEncoding = (dimensions, encoding, isMultiMeasure)=>{
    encoding.player = unique(dimensions.filter((item)=>'player' === item.encoding).map((item)=>item.id));
    encoding.x = unique(dimensions.filter((item)=>'xAxis' === item.encoding).map((item)=>item.id));
    if (0 === encoding.x.length) encoding.x = [
        dimensions[1].id
    ];
    addColorToEncoding(dimensions, encoding, isMultiMeasure);
    encoding.detail = unique(dimensions.filter((item)=>'detail' === item.encoding).map((item)=>item.id));
    if (0 === encoding.detail.length) encoding.detail = encoding.color;
    encoding.tooltip = unique(dimensions.map((item)=>item.id));
    encoding.tooltip = encoding.tooltip.filter((d)=>d !== MeasureId);
    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)=>'yAxis' === item.encoding || !item.encoding).map((item)=>item.id));
};
const generateMeasureEncoding = (measures, encoding)=>{
    encoding.y = unique(measures.filter((item)=>'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;
    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
    ]);
};
export { defaultEncodingForRaceColumn, encodingForRaceColumn };

//# sourceMappingURL=raceColumn.js.map