'use client' import { Note, NOTE_COLORS, NoteColor } from '@/lib/types' import { Card } from '@/components/ui/card' import { Pin, Bell } from 'lucide-react' import { useState } from 'react' import { deleteNote, toggleArchive, togglePin, updateColor, updateNote } from '@/app/actions/notes' import { cn } from '@/lib/utils' import { formatDistanceToNow } from 'date-fns' import { fr } from 'date-fns/locale' import { MarkdownContent } from './markdown-content' import { LabelBadge } from './label-badge' import { NoteImages } from './note-images' import { NoteChecklist } from './note-checklist' import { NoteActions } from './note-actions' import { useLabels } from '@/context/LabelContext' interface NoteCardProps { note: Note onEdit?: (note: Note) => void isDragging?: boolean isDragOver?: boolean } export function NoteCard({ note, onEdit, isDragging, isDragOver }: NoteCardProps) { const { refreshLabels } = useLabels() const [isDeleting, setIsDeleting] = useState(false) const colorClasses = NOTE_COLORS[note.color as NoteColor] || NOTE_COLORS.default const handleDelete = async () => { if (confirm('Are you sure you want to delete this note?')) { setIsDeleting(true) try { await deleteNote(note.id) // Refresh global labels to reflect garbage collection await refreshLabels() } catch (error) { console.error('Failed to delete note:', error) setIsDeleting(false) } } } const handleTogglePin = async () => { await togglePin(note.id, !note.isPinned) } const handleToggleArchive = async () => { await toggleArchive(note.id, !note.isArchived) } const handleColorChange = async (color: string) => { await updateColor(note.id, color) } const handleCheckItem = async (checkItemId: string) => { if (note.type === 'checklist' && note.checkItems) { const updatedItems = note.checkItems.map(item => item.id === checkItemId ? { ...item, checked: !item.checked } : item ) await updateNote(note.id, { checkItems: updatedItems }) } } if (isDeleting) return null return ( { // Only trigger edit if not clicking on buttons const target = e.target as HTMLElement if (!target.closest('button') && !target.closest('[role="checkbox"]')) { onEdit?.(note) } }} > {/* Pin Icon */} {note.isPinned && ( )} {/* Reminder Icon */} {note.reminder && new Date(note.reminder) > new Date() && ( )} {/* Title */} {note.title && (

{note.title}

)} {/* Images Component */} {/* Link Previews */} {note.links && note.links.length > 0 && (
{note.links.map((link, idx) => ( e.stopPropagation()} > {link.imageUrl && ( )} {/* Content */} {note.type === 'text' ? ( note.isMarkdown ? (
) : (

{note.content}

) ) : ( )} {/* Labels */} {note.labels && note.labels.length > 0 && (
{note.labels.map((label) => ( ))}
)} {/* Creation Date */}
{formatDistanceToNow(new Date(note.createdAt), { addSuffix: true, locale: fr })}
{/* Action Bar Component */} ) }