export const calculateParentSiblings = (node, allNodes) => {
    const hierarchy = node.hierarchy || 0;
    if (hierarchy === 0) {
        return []; // Root nodes have no parent connecting lines
    }
    const parentSiblings = [];
    const currentNodeIndex = allNodes.findIndex(n => n.key === node.key);
    if (currentNodeIndex === -1) {
        return new Array(hierarchy).fill(false);
    }
    // Build path from root to current node
    const path = getPathToNode(node, allNodes);
    // For each hierarchy level from 0 to hierarchy-1
    for (let level = 0; level < hierarchy; level++) {
        if (level === 0) {
            // Special case for level 0: check for more root children after this node
            const rootChildrenAfter = allNodes
                .slice(currentNodeIndex + 1)
                .filter(n => (n.hierarchy || 0) === 1); // Root children have hierarchy 1
            parentSiblings.push(rootChildrenAfter.length > 0);
        }
        else {
            // For other levels: find ancestor and check for siblings after
            const ancestor = path.find(n => (n.hierarchy || 0) === level);
            if (!ancestor) {
                parentSiblings.push(false);
                continue;
            }
            // Find children of this ancestor
            const ancestorChildren = allNodes.filter(n => n.parentId === ancestor.key);
            // Check if any child appears after the current node
            let hasChildrenAfter = false;
            for (const child of ancestorChildren) {
                const childIndex = allNodes.findIndex(n => n.key === child.key);
                if (childIndex > currentNodeIndex) {
                    hasChildrenAfter = true;
                    break;
                }
            }
            parentSiblings.push(hasChildrenAfter);
        }
    }
    return parentSiblings;
};
const getPathToNode = (node, allNodes) => {
    const path = [];
    let current = node;
    while (current) {
        path.unshift(current);
        if (!current.parentId)
            break;
        const found = allNodes.find(n => n.key === current.parentId);
        if (!found)
            break;
        current = found;
    }
    return path;
};
export const updateAllParentSiblings = (treeData) => {
    return treeData.map(node => ({
        ...node,
        parentSiblings: calculateParentSiblings(node, treeData),
    }));
};
//# sourceMappingURL=updateParentSibling.js.map