'use client' import { useState, type MouseEvent } from 'react' import Link from 'next/link' import { ChevronRight, FileText, Plus } from 'lucide-react' import { useTranslation } from 'react-i18next' import Tooltip from '@/shared/ui/Tooltip' import type { NoteSummary } from '@/lib/notes-api' export default function NotePageTree({ pages, currentId, busy, embedded = false, onNavigate, onCreate, }: { pages: NoteSummary[] currentId: string busy: boolean embedded?: boolean onNavigate: (event: MouseEvent, id: string) => void onClose?: () => void onCreate: (parentId: string | null) => void }) { const { t } = useTranslation() const [collapsed, setCollapsed] = useState>(() => new Set()) const rows = (parent: string | null, depth: number, ancestors = new Set()): React.ReactNode => { const children = pages .filter(p => p.parent_id === parent && !ancestors.has(p.id)) .sort((a, b) => Number(b.pinned) - Number(a.pinned)) if (!children.length) return null return (
    {children.map(page => { const title = page.title || t('Untitled') const hasChildren = pages.some(p => p.parent_id === page.id) const expanded = !collapsed.has(page.id) return (
  • {hasChildren ? ( ) : ( )} onNavigate(event, page.id)} aria-current={page.id === currentId ? 'page' : undefined} > {page.icon || } {title}
    {expanded && rows(page.id, depth + 1, new Set([...ancestors, page.id]))}
  • ) })}
) } return ( ) }