// NoteSelectionModal.jsx - Modal for selecting notes to add to chat context function NoteSelectionModal({ token, onSelect, onClose, t }) { const [notes, setNotes] = useState([]); const [selectedNoteIds, setSelectedNoteIds] = useState([]); const [searchQuery, setSearchQuery] = useState(''); const [loading, setLoading] = useState(true); useEffect(() => { fetchNotes(); }, []); const fetchNotes = async () => { try { setLoading(true); const response = await fetch(`${API_URL}/notes`, { headers: { 'Authorization': `Bearer ${token}` } }); const data = await response.json(); setNotes(data.notes || []); } catch (error) { console.error('Failed to fetch notes:', error); } finally { setLoading(false); } }; const filteredNotes = searchQuery ? notes.filter(note => note.title.toLowerCase().includes(searchQuery.toLowerCase()) || (note.subject && note.subject.toLowerCase().includes(searchQuery.toLowerCase())) ) : notes; const toggleNote = (noteId) => { setSelectedNoteIds(prev => prev.includes(noteId) ? prev.filter(id => id !== noteId) : [...prev, noteId] ); }; const handleCreate = () => { onSelect(selectedNoteIds); }; return (
e.stopPropagation()} style={{ background: 'white', borderRadius: '20px', width: '100%', maxWidth: '700px', maxHeight: '80vh', display: 'flex', flexDirection: 'column', boxShadow: '0 20px 60px rgba(0, 0, 0, 0.3)', overflow: 'hidden' }} > {/* Header */}

{t('ask.selectNotes') || 'Select Notes'}

{/* Search */} setSearchQuery(e.target.value)} style={{ width: '100%', padding: '0.75rem 1rem', borderRadius: '12px', border: '2px solid #e2e8f0', fontSize: '0.9375rem', outline: 'none', transition: 'border-color 0.2s' }} onFocus={e => e.target.style.borderColor = '#667eea'} onBlur={e => e.target.style.borderColor = '#e2e8f0'} />
{/* Notes List */}
{loading ? (

{t('common.loading') || 'Loading...'}

) : filteredNotes.length === 0 ? (
📝

{searchQuery ? (t('ask.noNotesFound') || 'No notes found') : (t('ask.noNotesAvailable') || 'No notes available')}

) : (
{filteredNotes.map(note => ( toggleNote(note.id)} /> ))}
)}
{/* Footer */}
{selectedNoteIds.length > 0 && ( {selectedNoteIds.length} selected )}
); } // Selectable Note Card function SelectableNoteCard({ note, isSelected, onToggle }) { const [isHovered, setIsHovered] = useState(false); return (
setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} style={{ padding: '1rem 1.25rem', borderRadius: '12px', border: `2px solid ${isSelected ? '#667eea' : '#e2e8f0'}`, background: isSelected ? 'rgba(102, 126, 234, 0.05)' : isHovered ? '#f8fafc' : 'white', cursor: 'pointer', transition: 'all 0.2s', position: 'relative' }} >
{/* Checkbox */}
{isSelected && ( )}
{/* Note Info */}
{note.title}
{note.subject && ( {note.subject} )} {note.block_count > 0 && ( 📝 {note.block_count} blocks )}
); } window.NoteSelectionModal = NoteSelectionModal;