'use client' import { useEffect, useState } from 'react' import { motion, AnimatePresence } from 'framer-motion' import { FileText, Loader2, Search, X } from 'lucide-react' import { useLanguage } from '@/lib/i18n' export interface NoteLinkOption { id: string title: string | null notebookId: string | null } interface NoteLinkPickerProps { isOpen: boolean query: string currentNoteId?: string onClose: () => void onSelect: (note: NoteLinkOption) => void } export function NoteLinkPicker({ isOpen, query, currentNoteId, onClose, onSelect, }: NoteLinkPickerProps) { const { t } = useLanguage() const [searchQuery, setSearchQuery] = useState(query) const [results, setResults] = useState([]) const [loading, setLoading] = useState(false) useEffect(() => { if (isOpen) setSearchQuery(query) }, [isOpen, query]) useEffect(() => { if (!isOpen) return setLoading(true) const timer = setTimeout(() => { const params = new URLSearchParams({ limit: '15' }) if (searchQuery.trim()) params.set('search', searchQuery.trim()) fetch(`/api/notes?${params}`) .then(r => r.json()) .then(data => { const notes: NoteLinkOption[] = (data.data || []) .filter((n: { id: string }) => n.id !== currentNoteId) .map((n: { id: string; title: string | null; notebookId: string | null }) => ({ id: n.id, title: n.title, notebookId: n.notebookId, })) setResults(notes) }) .catch(() => setResults([])) .finally(() => setLoading(false)) }, 250) return () => clearTimeout(timer) }, [isOpen, searchQuery, currentNoteId]) if (!isOpen) return null return (
e.stopPropagation()} >

{t('richTextEditor.noteLinkPickerTitle')}

{t('richTextEditor.noteLinkPickerHint')}

setSearchQuery(e.target.value)} placeholder={t('richTextEditor.noteLinkPickerSearch')} className="w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-muted/30 outline-none focus:ring-2 focus:ring-[#A47148]/30" onKeyDown={e => { if (e.key === 'Escape') onClose() }} />
{loading ? (
{t('common.loading')}
) : results.length === 0 ? (

{t('richTextEditor.noteLinkPickerEmpty')}

) : (
    {results.map(note => (
  • ))}
)}
) }