'use client' import { type ReactNode, useEffect, useState } from 'react' import type { PageTree } from 'fumadocs-core/server' import { ChevronRight } from 'lucide-react' import Link from 'next/link' import { usePathname } from 'next/navigation' import { cn } from '@/lib/utils' function isActive(url: string, pathname: string, nested = true): boolean { return url === pathname || (nested && pathname.startsWith(`${url}/`)) } export function SidebarItem({ item }: { item: PageTree.Item }) { const pathname = usePathname() const active = isActive(item.url, pathname, false) return (
{item.name}
) } function checkHasActiveChild(node: PageTree.Folder, pathname: string): boolean { if (node.index && isActive(node.index.url, pathname)) { return true } for (const child of node.children) { if (child.type === 'page' && isActive(child.url, pathname)) { return true } if (child.type === 'folder' && checkHasActiveChild(child, pathname)) { return true } } return false }