class CategoryTreeAdapter {
    constructor(tree){
        this.tree = tree;
    }
    toListItems() {
        const convertNodeManifest = (node)=>({
                id: node.nodeType,
                name: node.display.label,
                description: node.description,
                data: {
                    type: node.nodeType,
                    category: node.category,
                    version: node.version
                },
                ...node.display.icon ? {
                    icon: {
                        name: node.display.icon
                    }
                } : {},
                color: node.display.iconBackground,
                colorDark: node.display.iconBackgroundDark
            });
        const convertCategories = (categoryNodes)=>{
            const result = [];
            for (const category of categoryNodes){
                const children = [];
                const nestedCategoryItems = convertCategories(category.nestedCategories);
                children.push(...nestedCategoryItems);
                const nodeItems = category.nodes.map(convertNodeManifest);
                children.push(...nodeItems);
                if (0 === children.length) continue;
                const categoryItem = {
                    id: category.id,
                    name: category.name,
                    data: null,
                    ...category.icon ? {
                        icon: {
                            name: category.icon
                        }
                    } : {},
                    color: category.color,
                    colorDark: category.colorDark,
                    children
                };
                result.push(categoryItem);
            }
            return result;
        };
        const items = [];
        const categoryItems = convertCategories(this.tree.getRootCategories());
        items.push(...categoryItems);
        const rootNodes = this.tree.getRootNodes();
        const rootNodeItems = rootNodes.map(convertNodeManifest);
        items.push(...rootNodeItems);
        return items;
    }
}
export { CategoryTreeAdapter };
