import { memo } from 'react'; import type { Selection } from '@/hooks/use-planner'; import { formatRu, isWeekend, monthGrid, todayIso, WEEKDAYS_RU, MONTHS_RU, } from '@/lib/calendar'; import { stripes, tint } from '@/lib/marker-colors'; import { cn } from '@/lib/utils'; import type { Marker, VacationPeriod } from '@/types/planner'; export type DayInfo = { marker: Marker; period: VacationPeriod; }; type Props = { year: number; month0: number; dayMap: Map; selection: Selection | null; brushColor: string | null; onDayPointerDown: (date: string, pointerType: string) => boolean; onDayPointerEnter: (date: string) => void; onDayTouchTap: (date: string) => void; onDayInspect: (date: string) => void; }; export const MonthCalendar = memo(function MonthCalendar({ year, month0, dayMap, selection, brushColor, onDayPointerDown, onDayPointerEnter, onDayTouchTap, onDayInspect, }: Props) { const weeks = monthGrid(year, month0); const today = todayIso(); const selStart = selection && selection.start <= selection.end ? selection.start : selection?.end; const selEnd = selection && selection.start <= selection.end ? selection.end : selection?.start; return (
{MONTHS_RU[month0]}
{WEEKDAYS_RU.map((day, i) => (
= 5 && 'text-red-500/70 dark:text-red-400/70', )} > {day}
))} {weeks.flat().map((date, i) => { if (date === null) { return (
); } const entries = dayMap.get(date) ?? []; const inSelection = selStart !== undefined && selEnd !== undefined && date >= selStart && date <= selEnd; let background: string | undefined; if (entries.length === 1) { background = tint(entries[0].marker.color); } else if (entries.length > 1) { background = stripes( entries.map((e) => e.marker.color), ); } const markedNames = entries .map((e) => e.marker.name) .join(', '); return ( ); })}
); });