import { createFormatterByDimension, isDimensionGroup } from "../../../../utils/index.js";
import { treeTreeToColumns } from "./utils.js";
const dimensionTreeToColumns = (spec, context)=>{
    const { advancedVSeed } = context;
    const dimensionTree = advancedVSeed.dimensionTree;
    const result = {
        ...spec
    };
    const eachNode = (node)=>{
        const field = node.id;
        const title = node.alias ?? node.id;
        if (isDimensionGroup(node)) return {
            field,
            title,
            headerStyle: {
                textAlign: 'left'
            }
        };
        return {
            field,
            title,
            width: 'auto',
            style: {
                textAlign: 'left'
            },
            headerStyle: {
                textAlign: 'left'
            },
            fieldFormat: (datum)=>{
                const formatter = createFormatterByDimension(node, advancedVSeed.locale);
                return formatter(datum[node.id]);
            }
        };
    };
    const columns = treeTreeToColumns(dimensionTree, eachNode);
    return {
        ...result,
        columns: [
            ...result.columns || [],
            ...columns
        ]
    };
};
export { dimensionTreeToColumns };

//# sourceMappingURL=dimensionsToColumns.js.map