'use client' import { useState, useMemo } from 'react' import { NoteResponse } from '@/lib/types/api' import { Button } from '@/components/ui/button' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' import { Plus, StickyNote, Bot, User, MoreVertical, Trash2 } from 'lucide-react' import { LoadingSpinner } from '@/components/common/LoadingSpinner' import { EmptyState } from '@/components/common/EmptyState' import { Badge } from '@/components/ui/badge' import { NoteEditorDialog } from './NoteEditorDialog' import { formatDistanceToNow } from 'date-fns' import { ContextToggle } from '@/components/common/ContextToggle' import { ContextMode } from '../[id]/page' import { useDeleteNote } from '@/lib/hooks/use-notes' import { ConfirmDialog } from '@/components/common/ConfirmDialog' import { CollapsibleColumn, createCollapseButton } from '@/components/notebooks/CollapsibleColumn' import { useNotebookColumnsStore } from '@/lib/stores/notebook-columns-store' interface NotesColumnProps { notes?: NoteResponse[] isLoading: boolean notebookId: string contextSelections?: Record onContextModeChange?: (noteId: string, mode: ContextMode) => void } export function NotesColumn({ notes, isLoading, notebookId, contextSelections, onContextModeChange }: NotesColumnProps) { const [showAddDialog, setShowAddDialog] = useState(false) const [editingNote, setEditingNote] = useState(null) const [deleteDialogOpen, setDeleteDialogOpen] = useState(false) const [noteToDelete, setNoteToDelete] = useState(null) const deleteNote = useDeleteNote() // Collapsible column state const { notesCollapsed, toggleNotes } = useNotebookColumnsStore() const collapseButton = useMemo( () => createCollapseButton(toggleNotes, 'Notes'), [toggleNotes] ) const handleDeleteClick = (noteId: string) => { setNoteToDelete(noteId) setDeleteDialogOpen(true) } const handleDeleteConfirm = async () => { if (!noteToDelete) return try { await deleteNote.mutateAsync(noteToDelete) setDeleteDialogOpen(false) setNoteToDelete(null) } catch (error) { console.error('Failed to delete note:', error) } } return ( <>
Notes
{collapseButton}
{isLoading ? (
) : !notes || notes.length === 0 ? ( ) : (
{notes.map((note) => (
setEditingNote(note)} >
{note.note_type === 'ai' ? ( ) : ( )} {note.note_type === 'ai' ? 'AI Generated' : 'Human'}
{formatDistanceToNow(new Date(note.updated), { addSuffix: true })} {/* Context toggle - only show if handler provided */} {onContextModeChange && contextSelections?.[note.id] && (
event.stopPropagation()}> onContextModeChange(note.id, mode)} />
)} {/* Ellipsis menu for delete action */} { e.stopPropagation() handleDeleteClick(note.id) }} className="text-red-600 focus:text-red-600" > Delete Note
{note.title && (

{note.title}

)} {note.content && (

{note.content}

)}
))}
)}
{ if (!open) { setShowAddDialog(false) setEditingNote(null) } else { setShowAddDialog(true) } }} notebookId={notebookId} note={editingNote ?? undefined} /> ) }