"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderTree = void 0;
exports.renderTree = (root) => renderNode([], root, 0);
const getType = (node) => {
    if (node === null) {
        return 'null';
    }
    else if (Array.isArray(node)) {
        return 'array';
    }
    else {
        return typeof node;
    }
};
const renderNode = (treeList, node, level = 0, name = '') => {
    const type = getType(node);
    const baseNode = {
        id: Math.random().toString(36),
        level,
        name,
        type,
        metadata: {},
    };
    treeList.push(baseNode);
    if (type === 'array' || type === 'object') {
        baseNode.canHaveChildren = true;
        if (type === 'array') {
            baseNode.metadata.value = node.length;
            for (const [i, n] of node.entries()) {
                renderNode(treeList, n, level + 1, String(i));
            }
        }
        else {
            baseNode.metadata.value = Object.keys(node).length;
            for (const [i, property] of Object.entries(node)) {
                renderNode(treeList, property, level + 1, i);
            }
        }
    }
    else {
        baseNode.metadata.value = node;
    }
    return treeList;
};
//# sourceMappingURL=renderNode.js.map