import React from 'react'; import { Note, Project } from '../types'; import { motion } from 'motion/react'; interface CalendarViewProps { notes: Record; projects: Project[]; onNavigateToNote: (noteId: string) => void; onFilterDate?: (dateStr: string) => void; } export const CalendarView: React.FC = ({ notes, projects, onNavigateToNote, onFilterDate }) => { const [currentDate, setCurrentDate] = React.useState(new Date()); const getDaysInMonth = (year: number, month: number) => { return new Date(year, month + 1, 0).getDate(); }; const getFirstDayOfMonth = (year: number, month: number) => { return new Date(year, month, 1).getDay(); }; const year = currentDate.getFullYear(); const month = currentDate.getMonth(); const daysInMonth = getDaysInMonth(year, month); const firstDay = getFirstDayOfMonth(year, month); const days = Array.from({ length: daysInMonth }, (_, i) => i + 1); const padding = Array.from({ length: firstDay === 0 ? 6 : firstDay - 1 }, (_, i) => i); // Adjust for Monday start const notesByDate: Record = {}; Object.values(notes).forEach(note => { const date = new Date(note.timestamp).toDateString(); if (!notesByDate[date]) notesByDate[date] = []; notesByDate[date].push(note); }); const nextMonth = () => setCurrentDate(new Date(year, month + 1, 1)); const prevMonth = () => setCurrentDate(new Date(year, month - 1, 1)); const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; return (

{monthNames[month]} {year}

{["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"].map(day => (
{day}
))} {padding.map(i =>
)} {days.map(day => { const date = new Date(year, month, day).toDateString(); const dayNotes = notesByDate[date] || []; const isToday = new Date().toDateString() === date; return (
{ const dateStr = new Date(year, month, day).toLocaleDateString('en-US', { day: 'numeric', month: 'short' }).toUpperCase(); onFilterDate && onFilterDate(dateStr); }} className={`aspect-square rounded-2xl border p-2 flex flex-col gap-1 transition-all cursor-pointer ${ isToday ? 'bg-indigo-500/10 border-indigo-500/40 hover:bg-indigo-500/20' : 'bg-white/[0.02] border-white/5 hover:border-white/10 hover:bg-white/[0.05]' }`} > {day}
{dayNotes.map(note => ( ))}
); })}
); };