'use client' import { useState } from 'react' import { ProcessTask, daysUntil } from './types' export function CalendarView({ tasks }: { tasks: ProcessTask[] }) { const [currentMonth, setCurrentMonth] = useState(() => { const now = new Date() return new Date(now.getFullYear(), now.getMonth(), 1) }) const year = currentMonth.getFullYear() const month = currentMonth.getMonth() const daysInMonth = new Date(year, month + 1, 0).getDate() const firstDayOfWeek = new Date(year, month, 1).getDay() const startOffset = firstDayOfWeek === 0 ? 6 : firstDayOfWeek - 1 const monthLabel = currentMonth.toLocaleDateString('de-DE', { month: 'long', year: 'numeric' }) const tasksByDate: Record = {} tasks.forEach(t => { if (!t.next_due_date) return const key = t.next_due_date.substring(0, 10) if (!tasksByDate[key]) tasksByDate[key] = [] tasksByDate[key].push(t) }) const prev = () => setCurrentMonth(new Date(year, month - 1, 1)) const next = () => setCurrentMonth(new Date(year, month + 1, 1)) const today = new Date().toISOString().substring(0, 10) return (

{monthLabel}

{['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'].map(d => (
{d}
))} {Array.from({ length: startOffset }).map((_, i) => (
))} {Array.from({ length: daysInMonth }).map((_, i) => { const day = i + 1 const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}` const dayTasks = tasksByDate[dateStr] || [] const isToday = dateStr === today return (
{day}
{dayTasks.slice(0, 3).map(t => { const days = daysUntil(t.next_due_date) let dotColor = 'bg-gray-400' if (t.status === 'completed') dotColor = 'bg-green-500' else if (days !== null && days < 0) dotColor = 'bg-red-500' else if (days !== null && days <= 7) dotColor = 'bg-orange-500' return (
{t.title}
) })} {dayTasks.length > 3 && ( +{dayTasks.length - 3} mehr )}
) })}
) }