'use client' import { Notebook } from '@/lib/types' interface NotebookTreeSelectProps { notebooks: Notebook[] value: string | null onChange: (notebookId: string | null) => void placeholder?: string inboxLabel?: string className?: string } export function buildNotebookTree(notebooks: Notebook[]): { roots: Notebook[]; children: Map } { const roots: Notebook[] = [] const children = new Map() for (const nb of notebooks) { if (nb.parentId) { const arr = children.get(nb.parentId) || [] arr.push(nb) children.set(nb.parentId, arr) } else { roots.push(nb) } } return { roots, children } } export function NotebookTreeSelect({ notebooks, value, onChange, placeholder, inboxLabel, className }: NotebookTreeSelectProps) { const { roots, children } = buildNotebookTree(notebooks) return ( ) } export function NotebookTreeList({ notebooks, activeNotebookId, onSelect, inboxLabel }: { notebooks: Notebook[] activeNotebookId: string | null onSelect: (notebookId: string | null) => void inboxLabel?: string }) { const { roots, children } = buildNotebookTree(notebooks) return ( <> {inboxLabel && ( )} {roots.map(nb => (
{(children.get(nb.id) || []).map(child => ( ))}
))} ) }