import { unique } from "remeda";
import { MeasureId } from "../../../../../dataReshape/index.js";
import { addColorToEncoding } from "./color/index.js";
const defaultEncodingForHistogram = (advancedVSeed)=>{
    const { measures = [], dimensions = [] } = advancedVSeed;
    const encoding = {};
    generateDefaultDimensionEncoding(dimensions, encoding);
    generateDefaultMeasureEncoding(measures, encoding);
    return {
        ...advancedVSeed,
        encoding
    };
};
const encodingForHistogram = (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, false);
    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)=>d !== MeasureId);
    encoding.label = [];
    encoding.row = [];
    encoding.column = [];
};
const generateDimensionEncoding = (dimensions, encoding, isMultiMeasure)=>{
    addColorToEncoding(dimensions, encoding, isMultiMeasure);
    encoding.detail = unique(dimensions.filter((item)=>'detail' === item.encoding).map((item)=>item.id));
    if (encoding.detail?.length === 0) 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.value = unique(measures.filter((item)=>'value' === item.encoding || !item.encoding).map((item)=>item.id));
    encoding.x0 = unique(measures.filter((item)=>'x0' === item.encoding).map((item)=>item.id));
    encoding.x1 = unique(measures.filter((item)=>'x1' === item.encoding).map((item)=>item.id));
    encoding.y = unique(measures.filter((item)=>'yAxis' === item.encoding).map((item)=>item.id));
};
const generateMeasureEncoding = (measures, encoding)=>{
    encoding.value = unique(measures.filter((item)=>'value' === item.encoding || !item.encoding).map((item)=>item.id));
    encoding.x0 = unique(measures.filter((item)=>'x0' === item.encoding).map((item)=>item.id));
    encoding.x1 = unique(measures.filter((item)=>'x1' === item.encoding).map((item)=>item.id));
    encoding.y = unique(measures.filter((item)=>'yAxis' === 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]
    ];
    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 { defaultEncodingForHistogram, encodingForHistogram };

//# sourceMappingURL=histogram.js.map