const isRow = (node) => node.tag === "arcgis-layout-row";
/**
 * Recursively traverses a layout to find a node with the supplied id.
 */
export function findNodeById(layout, nodeId) {
    var _a;
    if (!layout.sections || !layout.sections.length) {
        return undefined;
    }
    for (const section of layout.sections) {
        if (section.id === nodeId) {
            return section;
        }
        if (!section.children) {
            continue;
        }
        for (const row of section.children) {
            if (row.id === nodeId) {
                return row;
            }
            if (!row.children) {
                continue;
            }
            for (const column of row.children) {
                if (column.id === nodeId) {
                    return column;
                }
                if (!column.children) {
                    continue;
                }
                for (const child of column.children) {
                    if (child.id === nodeId) {
                        return child;
                    }
                    if (child.tag === "arcgis-nav-card") {
                        const navCardSections = (_a = child.properties) === null || _a === void 0 ? void 0 : _a.sections;
                        const result = findNodeById({ sections: navCardSections || [] }, nodeId);
                        if (result) {
                            return result;
                        }
                    }
                    if (isRow(child) && child.children) {
                        const result = findNodeById({ sections: [{ children: [child] }] }, nodeId);
                        if (result) {
                            return result;
                        }
                    }
                }
            }
        }
    }
    return undefined;
}
//# sourceMappingURL=findNodeById.js.map