// Recursively create bookmarks from nodes
export async function createBookmarks(nodes, parentId) {
    for (const node of nodes) {
        if (node.url) {
            await chrome.bookmarks.create({ parentId, title: node.title, url: node.url });
        } else {
            const newFolder = await chrome.bookmarks.create({ parentId, title: node.title });
            if (node.children && node.children.length > 0) {
                await createBookmarks(node.children, newFolder.id);
            }
        }
    }
}

// Recursively delete all children
export async function removeBookmarks(parentId) {
    const children = await chrome.bookmarks.getChildren(parentId);
    if (!children || children.length === 0) return;

    for (let i = 0; i < children.length; i++) {
        const child = children[i];
        if (child.url) {
            await chrome.bookmarks.remove(child.id);
        }
        else {
            await removeBookmarks(child.id);
            await chrome.bookmarks.remove(child.id);
        };
    }
}