import { DEFAULT_RENDER_KEY, } from './common';
export default function getJudgeInfo(_a) {
    var expandAll = _a.expandAll, loadMore = _a.loadMore, tree = _a.tree, _b = _a.renderKey, renderKey = _b === void 0 ? DEFAULT_RENDER_KEY : _b;
    var expandNode = [];
    var rootInfoMap = {};
    var children = renderKey.children, id = renderKey.id;
    function collector(_a) {
        var nodeTree = _a.nodeTree, parentId = _a.parentId;
        nodeTree.forEach(function (item) {
            var nodeId = item[id];
            rootInfoMap[nodeId] = {
                id: nodeId,
                parentId: parentId,
                root: item,
                isExpand: false,
                isParent: false,
                son: (item[children] || []).map(function (t) { return t[id]; }),
                rootIncludeIds: [nodeId],
            };
            var isParentNode = !!(!item.isLeaf &&
                (loadMore || (item[children] && item[children].length > 0)));
            rootInfoMap[nodeId].isParent = isParentNode;
            if (isParentNode && (expandAll || !!item.expand)) {
                expandNode.push(nodeId);
            }
            if (item[children]) {
                collector({
                    nodeTree: item[children],
                    parentId: nodeId,
                });
            }
            if (parentId !== undefined && rootInfoMap[parentId]) {
                rootInfoMap[parentId].rootIncludeIds = rootInfoMap[parentId].rootIncludeIds.concat(rootInfoMap[nodeId].rootIncludeIds);
            }
        });
    }
    collector({
        nodeTree: tree,
        parentId: undefined,
    });
    return {
        rootInfoMap: rootInfoMap,
        expandNode: expandNode,
    };
}
