"use client"; import { useMemo, useState } from "react"; export type CalendarMarker = { date: Date; status: "pending" | "confirmed" | "rejected" | "cancelled" | "past" | "public" | "private"; }; const WEEKDAY_LABELS = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"]; const markerColor: Record = { pending: "bg-anouma-sand", confirmed: "bg-anouma-sage", rejected: "bg-red-400", cancelled: "bg-anouma-taupe", past: "bg-anouma-taupe/50", public: "bg-anouma-rose", private: "bg-anouma-mauve-dark", }; function startOfMonth(d: Date) { return new Date(d.getFullYear(), d.getMonth(), 1); } function dateKey(d: Date) { return d.toISOString().slice(0, 10); } export function MonthCalendar({ markers, onSelectDay, selectedDay, }: { markers: CalendarMarker[]; onSelectDay?: (day: Date) => void; selectedDay?: Date | null; }) { const [month, setMonth] = useState(() => startOfMonth(new Date())); const markersByDay = useMemo(() => { const map = new Map(); for (const marker of markers) { const key = dateKey(marker.date); map.set(key, [...(map.get(key) ?? []), marker]); } return map; }, [markers]); const weeks = useMemo(() => { const first = startOfMonth(month); const firstWeekday = (first.getDay() + 6) % 7; // Monday = 0 const daysInMonth = new Date(month.getFullYear(), month.getMonth() + 1, 0).getDate(); const cells: (Date | null)[] = Array(firstWeekday).fill(null); for (let d = 1; d <= daysInMonth; d++) { cells.push(new Date(month.getFullYear(), month.getMonth(), d)); } while (cells.length % 7 !== 0) cells.push(null); const result: (Date | null)[][] = []; for (let i = 0; i < cells.length; i += 7) result.push(cells.slice(i, i + 7)); return result; }, [month]); const monthLabel = month.toLocaleDateString("de-DE", { month: "long", year: "numeric" }); const today = dateKey(new Date()); return (

{monthLabel}

{WEEKDAY_LABELS.map((d) => (
{d}
))}
{weeks.map((week, i) => (
{week.map((day, j) => { if (!day) return
; const key = dateKey(day); const dayMarkers = markersByDay.get(key) ?? []; const isSelected = selectedDay && dateKey(selectedDay) === key; return ( ); })}
))}
); }