import { AngleEncoding, ColorEncoding, ColorIdEncoding, DetailEncoding, HierarchyEncoding, MeasureId, MeasureName, PlayerEncoding, XEncoding, YEncoding } from "./constant.js";
const unfoldDimensions = (dataset, dimensions, encoding, options)=>{
    const { separator, formatDimensionValue } = options;
    const unfoldInfo = {
        encodingAngle: AngleEncoding,
        encodingX: XEncoding,
        encodingY: YEncoding,
        encodingDetail: DetailEncoding,
        encodingColor: ColorEncoding,
        encodingColorId: ColorIdEncoding,
        encodingPlayer: PlayerEncoding,
        encodingHierarchy: HierarchyEncoding,
        colorItems: [],
        colorIdMap: {}
    };
    const { color, x, y, detail, angle, player, hierarchy } = encoding;
    const angleDimensions = angle ? dimensions.filter((dim)=>angle.includes(dim.id)) : [];
    const xDimensions = x ? dimensions.filter((dim)=>x.includes(dim.id)) : [];
    const yDimensions = y ? dimensions.filter((dim)=>y.includes(dim.id)) : [];
    const colorDimensions = color ? dimensions.filter((dim)=>color.includes(dim.id)) : [];
    const detailDimensions = detail ? dimensions.filter((dim)=>detail.includes(dim.id)) : [];
    const playerDimensions = player ? dimensions.filter((dim)=>player.includes(dim.id)) : [];
    const hierarchyDimensions = hierarchy ? dimensions.filter((dim)=>hierarchy.includes(dim.id)) : [];
    const colorItems = new Set();
    const colorIdMap = {};
    for(let i = 0; i < dataset.length; i++){
        const datum = dataset[i];
        applyEncoding(AngleEncoding, angleDimensions, datum, separator);
        applyEncoding(XEncoding, xDimensions, datum, separator);
        applyEncoding(YEncoding, yDimensions, datum, separator);
        applyEncoding(ColorEncoding, colorDimensions, datum, separator);
        applyEncoding(DetailEncoding, detailDimensions, datum, separator);
        applyEncoding(PlayerEncoding, playerDimensions, datum, separator);
        applyEncoding(HierarchyEncoding, hierarchyDimensions, datum, separator);
        if (!colorDimensions.length || !datum[ColorEncoding]) continue;
        const colorId = String(datum[ColorEncoding] ?? '');
        datum[ColorIdEncoding] = colorId;
        colorIdMap[colorId] = {
            id: colorId,
            alias: getColorAliasItem(ColorEncoding, colorDimensions, datum, separator, formatDimensionValue)
        };
        colorItems.add(colorId);
    }
    unfoldInfo.colorItems = Array.from(colorItems);
    unfoldInfo.colorIdMap = colorIdMap;
    return {
        dataset,
        unfoldInfo
    };
};
const applyEncoding = (encoding, dimensions, datum, separator)=>{
    if (encoding && dimensions.length) datum[encoding] = dimensions.map((dim)=>String(datum[dim.id])).join(separator);
};
const getColorAliasItem = (encoding, dimensions, datum, separator, formatDimensionValue)=>{
    if (encoding && dimensions.length) return dimensions.map((dim)=>{
        if (dim.id === MeasureId) return String(datum[MeasureName]);
        const rawValue = datum[dim.id];
        return formatDimensionValue ? formatDimensionValue(dim, rawValue) : String(rawValue);
    }).join(separator);
    return '';
};
export { unfoldDimensions };

//# sourceMappingURL=unfoldDimensions.js.map