// src/components/TableOfContents.tsx import type { Heading } from '@/lib/lexical-headings' interface TableOfContentsProps { headings: Heading[] title?: string showTitle?: boolean } function flatten( list: Heading[], depth = 0, acc: Array = [], ): Array { for (const h of list) { acc.push({ ...h, depth }) if (h.children?.length) flatten(h.children, depth + 1, acc) } return acc } export function TableOfContents({ headings, title = 'Contents', showTitle = true, }: TableOfContentsProps) { const flat = flatten(headings) if (flat.length === 0) return null return ( ) }