'use client' import { useState, type MouseEvent } from 'react' import Link from 'next/link' import { ChevronRight, FileText, Pin, Plus, X } from 'lucide-react' import { useTranslation } from 'react-i18next' import type { NoteSummary } from '@/lib/notes-api' export default function NotePageTree({ pages, currentId, busy, onNavigate, onClose, onCreate }: { pages: NoteSummary[] currentId: string busy: boolean onNavigate: (event: MouseEvent, id: string) => void onClose: () => void onCreate: () => void }) { const { t } = useTranslation() const [collapsed, setCollapsed] = useState>(() => new Set()) const rows = (parent: string | null, 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 page') const hasChildren = pages.some(p => p.parent_id === page.id) const expanded = !collapsed.has(page.id) return
  • {hasChildren ? : } onNavigate(event, page.id)} title={title} aria-current={page.id === currentId ? 'page' : undefined}> {page.icon || } {title} {page.pinned && }
    {expanded && rows(page.id, new Set([...ancestors, page.id]))}
  • })}
} return }