import { createFormatterByMeasure, isMeasureGroup } from "../../../../utils/index.js";
import { treeTreeToColumns } from "./utils.js";
import { isNullish } from "remeda";
import { isUndefined } from "@visactor/vutils";
const measureTreeToColumns = (spec, context)=>{
    const { advancedVSeed } = context;
    const measureTree = advancedVSeed.measureTree;
    const result = {
        ...spec
    };
    const eachNode = (node)=>{
        const field = node.id;
        const title = node.alias ?? node.id;
        if (isMeasureGroup(node)) return {
            field,
            title,
            headerStyle: {
                textAlign: 'right'
            }
        };
        return {
            field,
            title,
            width: 'auto',
            style: {
                textAlign: 'right'
            },
            headerStyle: {
                textAlign: 'right'
            },
            fieldFormat: fieldFormat(node)
        };
    };
    const columns = treeTreeToColumns(measureTree, eachNode);
    return {
        ...result,
        columns: [
            ...result.columns || [],
            ...columns
        ]
    };
};
const fieldFormat = (node)=>{
    const formatter = createFormatterByMeasure(node);
    return (datum)=>{
        const { id } = node;
        const value = datum[id];
        if (isNullish(value) || isUndefined(value)) return value;
        return formatter(value);
    };
};
export { measureTreeToColumns };

//# sourceMappingURL=measuresToColumns.js.map