'use client'; import React, { useState, useMemo } from 'react'; interface Prayer { id: string; date: string; text: string; prayFor?: string; } interface CalendarViewProps { prayers: Prayer[]; onDayClick: (date: string) => void; } export default function CalendarView({ prayers, onDayClick }: CalendarViewProps) { const [currentMonth, setCurrentMonth] = useState(new Date()); const daysWithEntries = useMemo(() => { return new Set(prayers.map(p => p.date)); }, [prayers]); const getDaysInMonth = (date: Date) => { return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate(); }; const getFirstDayOfMonth = (date: Date) => { return new Date(date.getFullYear(), date.getMonth(), 1).getDay(); }; const daysInMonth = getDaysInMonth(currentMonth); const firstDay = getFirstDayOfMonth(currentMonth); const prevMonth = () => setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1)); const nextMonth = () => setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1)); const days = []; for (let i = 0; i < firstDay; i++) { days.push(null); } for (let i = 1; i <= daysInMonth; i++) { days.push(i); } return (
{/* Header */}

Prayer Journal

Click on days with entries to view them

{/* Calendar */}
{/* Month Navigation */}

{currentMonth.toLocaleDateString('en-US', { month: 'long', year: 'numeric' })}

{/* Day Headers */}
{['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'].map(day => (
{day}
))}
{/* Calendar Days */}
{days.map((day, index) => { const dateString = day !== null ? `${currentMonth.getFullYear()}-${String(currentMonth.getMonth() + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}` : null; const hasEntry = dateString ? daysWithEntries.has(dateString) : false; const prayerCount = dateString ? prayers.filter(p => p.date === dateString).length : 0; return ( ); })}
{/* Stats */}

Total Entries

{prayers.length}

Days with Entries

{daysWithEntries.size}

); }