import { useEffect, useMemo, useRef, type DragEvent as ReactDragEvent, } from "react"; import { i18nMessage } from "@govoplan/core-webui"; import type { CalendarEvent } from "../../api/calendar"; import { HOUR_ROW_HEIGHT, INITIAL_SCROLL_HOUR, calendarEventColorStyle, chunk, continuousVirtualWindow, dayKey, dayMonthLabel, dropSlotMinuteOfDay, eventTimeLabel, isWeekend, layoutTimedEventsForDay, minuteOfDayLabel, monthYearLabel, sameDay, sameMonth, timedEventStyle, timedOverflowStyle, timeGridStyle, weekdayLong, type CalendarDropTarget, type CalendarMode, type CalendarResizeEdge, type CalendarTimeDropTarget, type CalendarViewPreferences, type ContinuousViewport, } from "./calendarViewModel"; type CalendarViewCallbacks = { onEventSelect: (event: CalendarEvent) => void; onEventHover: (eventId: string) => void; onEventDragStart: ( dragEvent: ReactDragEvent, event: CalendarEvent, ) => void; onEventDragEnd: () => void; onEventDragOverDay: ( dragEvent: ReactDragEvent, day: Date, ) => void; onDropTargetLeave: ( dragEvent: ReactDragEvent, ) => void; onEventDropOnDay: ( dropEvent: ReactDragEvent, day: Date, ) => void; }; type CalendarWeekRowsProps = CalendarViewCallbacks & { days: Date[]; eventsByDay: Map; calendarColorById: Map; focusDate: Date; variant: "month" | "continuous"; preferences: CalendarViewPreferences; canWrite: boolean; draggingEventId: string; hoveredEventId: string; dropTarget: CalendarDropTarget; viewport?: ContinuousViewport; }; export function CalendarWeekRows({ days, eventsByDay, calendarColorById, focusDate, variant, preferences, canWrite, draggingEventId, hoveredEventId, dropTarget, viewport, onEventSelect, onEventHover, onEventDragStart, onEventDragEnd, onEventDragOverDay, onDropTargetLeave, onEventDropOnDay, }: CalendarWeekRowsProps) { const weeks = chunk(days, 7); const virtualWindow = variant === "continuous" && preferences.continuousVirtualization ? continuousVirtualWindow( weeks.length, viewport ?? { scrollTop: 0, height: 0 }, preferences.continuousOverscanWeeks, ) : { start: 0, end: weeks.length, topSpacerHeight: 0, bottomSpacerHeight: 0, }; const visibleWeeks = weeks.slice( virtualWindow.start, virtualWindow.end, ); const eventLimit = variant === "month" ? 5 : 3; return (
{[ "i18n:govoplan-calendar.mon.24b2a099", "i18n:govoplan-calendar.tue.529541bb", "i18n:govoplan-calendar.wed.23408b19", "i18n:govoplan-calendar.thu.3593ccd9", "i18n:govoplan-calendar.fri.bbd6e32e", "i18n:govoplan-calendar.sat.6b782d41", "i18n:govoplan-calendar.sun.48c98cab", ].map((label) => ( {label} ))}
{virtualWindow.topSpacerHeight > 0 && (