const KB_OBJECT_TYPE = "type";
export const KB_OBJECT = "object";
const convertObjectDataToTreeItem = (objectTypeIcon, objectItems) => {
    return objectItems.map(objectItem => ({
        id: objectItem.id,
        caption: objectItem.name,
        startImgSrc: objectTypeIcon,
        expanded: true,
        leaf: true,
        metadata: KB_OBJECT
    }));
};
export const convertObjectTypeDataToTreeView = (objectTypeData) => {
    const treeData = [];
    if (!objectTypeData) {
        return treeData;
    }
    for (const objectType of objectTypeData) {
        if (objectType.items.length > 0) {
            treeData.push({
                id: objectType.id,
                caption: objectType.name,
                startImgSrc: objectType.icon,
                expanded: true,
                leaf: false,
                metadata: KB_OBJECT_TYPE,
                items: convertObjectDataToTreeItem(objectType.icon, objectType.items)
            });
        }
    }
    return treeData;
};
export const createArrayOfItems = (objectItems, objectTypes) => {
    // The resulting array with 'items' property added to each type
    const objectTypesWithItems = objectTypes.map(type => {
        // Filter objects that match the current type id
        const items = objectItems.filter(object => object.type === type.id);
        // Return a new object type with the 'items' property
        return Object.assign(Object.assign({}, type), { items: items });
    });
    const treeView = convertObjectTypeDataToTreeView(objectTypesWithItems);
    return treeView;
};
//# sourceMappingURL=helpers.js.map
