'use client'; import React, { useState } from 'react'; import { BookOpen, Search, Plus, Trash2, Tag, Pin, Smile, X, Sparkles, Heart } from 'lucide-react'; import { Note } from '@/lib/types'; import { getFormattedDate } from '@/lib/initialData'; import { playNotificationChime } from '@/lib/audio'; interface NotesViewProps { notes: Note[]; onAddNote: (note: Omit) => void; onUpdateNote: (id: string, updates: Partial) => void; onDeleteNote: (id: string) => void; showAddModalDefault?: boolean; } export const NotesView: React.FC = ({ notes, onAddNote, onUpdateNote, onDeleteNote, showAddModalDefault = false, }) => { const [searchQuery, setSearchQuery] = useState(''); const [selectedCategory, setSelectedCategory] = useState('all'); const [isModalOpen, setIsModalOpen] = useState(showAddModalDefault); // Form state const [title, setTitle] = useState(''); const [content, setContent] = useState(''); const [tagsInput, setTagsInput] = useState(''); const [category, setCategory] = useState('Tech'); const [mood, setMood] = useState<1 | 2 | 3 | 4 | 5>(4); const [pinned, setPinned] = useState(false); const moodEmojis: Record = { 1: { emoji: '😫', label: 'Stressed' }, 2: { emoji: '😴', label: 'Tired' }, 3: { emoji: '😐', label: 'Neutral' }, 4: { emoji: '😊', label: 'Energized' }, 5: { emoji: '🚀', label: 'Unstoppable' }, }; const handleCreate = (e: React.FormEvent) => { e.preventDefault(); if (!title.trim()) return; const tags = tagsInput .split(',') .map((t) => t.trim()) .filter((t) => t.length > 0); onAddNote({ title: title.trim(), content: content.trim(), tags, category: category.trim() || 'General', mood, pinned, }); setTitle(''); setContent(''); setTagsInput(''); setIsModalOpen(false); playNotificationChime('click'); }; const categories = ['all', ...Array.from(new Set(notes.map((n) => n.category)))]; const filteredNotes = notes.filter((n) => { const matchesSearch = n.title.toLowerCase().includes(searchQuery.toLowerCase()) || n.content.toLowerCase().includes(searchQuery.toLowerCase()) || n.tags.some((t) => t.toLowerCase().includes(searchQuery.toLowerCase())); const matchesCat = selectedCategory === 'all' || n.category === selectedCategory; return matchesSearch && matchesCat; }); // Sort pinned first const sortedNotes = [...filteredNotes].sort((a, b) => (b.pinned ? 1 : 0) - (a.pinned ? 1 : 0)); return (
{/* Top Bar: Search, Category Filter, New Note Button */}
{/* Search */}
setSearchQuery(e.target.value)} className="w-full pl-9 pr-4 py-2 rounded-xl bg-slate-900 border border-slate-800 text-sm text-slate-200 placeholder-slate-500 focus:outline-none focus:border-purple-500 transition-colors" />
{/* Category Pills */}
{categories.map((cat) => ( ))}
{/* Notes Grid */}
{sortedNotes.map((note) => (
{/* Header: Category, Mood, Pin, Delete */}
{note.category}
{note.mood && ( {moodEmojis[note.mood]?.emoji} )}
{/* Note Title */}

{note.title}

{/* Note Content */}
{note.content}
{/* Footer: Tags & Date */}
{note.tags.map((t) => ( {t} ))}
{note.updatedAt}
))} {sortedNotes.length === 0 && (

No notes found matching your criteria.

)}
{/* Create Note Modal */} {isModalOpen && (

Capture Note & Reflection

setTitle(e.target.value)} className="w-full px-3.5 py-2.5 rounded-xl bg-slate-900 border border-slate-800 text-sm text-slate-100 placeholder-slate-500 focus:outline-none focus:border-purple-500" />