"use client";
import { cn } from "./index3.js";
import { CurrentTimeMarker } from "./index56.js";
import { getDateKey, parseEventDate } from "./index57.js";
import "./index58.js";
import { TimeGrid } from "./index62.js";
import { DayColumn } from "./index63.js";
import { useCurrentTime } from "./index67.js";
import { useCalendarContext } from "./index76.js";
import * as React from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { addDays, format, isToday, isWeekend, startOfWeek } from "date-fns";
//#region src/components/molecules/data/Calendar/WeekView.tsx
var EMPTY_EVENTS = [];
function WeekView({ startHour = 0, endHour = 24, onEventClick }) {
	const { events, selectedDate, weekStartsOn } = useCalendarContext();
	const weekStart = startOfWeek(selectedDate, { weekStartsOn });
	const days = Array.from({ length: 7 }, (_, i) => addDays(weekStart, i));
	const eventsByDate = React.useMemo(() => {
		const map = /* @__PURE__ */ new Map();
		for (const event of events) {
			const key = getDateKey(parseEventDate(event.start));
			const list = map.get(key);
			if (list) list.push(event);
			else map.set(key, [event]);
		}
		return map;
	}, [events]);
	const getEventsForDay = (date) => eventsByDate.get(getDateKey(date)) ?? EMPTY_EVENTS;
	const { now, top: timeMarkerTop, visible: showMarker } = useCurrentTime(startHour, endHour, days.some((day) => isToday(day)));
	return /* @__PURE__ */ jsxs("div", {
		"data-slot": "week-view",
		role: "region",
		"aria-label": "Week calendar",
		children: [/* @__PURE__ */ jsxs("div", {
			className: "grid [grid-template-columns:72px_repeat(5,1fr)] @[768px]:[grid-template-columns:72px_repeat(7,1fr)]",
			children: [/* @__PURE__ */ jsx("div", { className: "border-b border-border" }), days.map((day) => {
				const isTodayDate = isToday(day);
				return /* @__PURE__ */ jsxs("div", {
					className: cn("flex flex-col items-center gap-0.5 border-b border-l border-border px-2 py-2", isWeekend(day) && "hidden @[768px]:flex bg-surface-1"),
					children: [/* @__PURE__ */ jsx("span", {
						className: "text-xs font-medium text-muted-foreground",
						children: format(day, "EEE")
					}), /* @__PURE__ */ jsx("span", {
						className: cn("flex size-7 items-center justify-center text-sm font-semibold", isTodayDate && `rounded-sm bg-primary text-primary-foreground shadow-[0_0_0_2px_hsl(var(--primary)/0.2)]`, !isTodayDate && "text-foreground"),
						children: format(day, "d")
					})]
				}, day.toISOString());
			})]
		}), /* @__PURE__ */ jsxs(TimeGrid, {
			startHour,
			endHour,
			children: [/* @__PURE__ */ jsx("div", {
				className: "grid h-full [grid-template-columns:repeat(5,1fr)] @[768px]:[grid-template-columns:repeat(7,1fr)]",
				children: days.map((day) => {
					const isWeekendDay = isWeekend(day);
					return /* @__PURE__ */ jsx(DayColumn, {
						date: day,
						events,
						dayEvents: getEventsForDay(day),
						startHour,
						endHour,
						onEventClick,
						className: cn(isWeekendDay && "hidden @[768px]:block")
					}, day.toISOString());
				})
			}), showMarker && /* @__PURE__ */ jsx(CurrentTimeMarker, {
				top: timeMarkerTop,
				now
			})]
		})]
	});
}
WeekView.displayName = "WeekView";
//#endregion
export { WeekView };

//# sourceMappingURL=index70.js.map