import { dayOccupancy, sameSlot } from "../../utils/bookingCalendarDateUtils.js";
import { useCallback } from "react";
//#region src/components/pisellRecordBoard/shellFrame/Calendar/view/day/useBookingCalendarDaySelection.ts
/**
* 日视图：空闲 / 锁台槽多选逻辑（状态仍在 Shell，便于与底部 SelectionBar 共用）。
*/
function useBookingCalendarDaySelection(dayKey, bookings, hourSlots, slotStepHours, courts, selectedFreeSlots, selectedBlockSlots, setSelectedFreeSlots, setSelectedBlockSlots) {
	return {
		isFreeSelected: useCallback((courtId, hour) => selectedFreeSlots.some((slot) => slot.courtId === courtId && slot.date === dayKey && slot.hour === hour), [selectedFreeSlots, dayKey]),
		isBlockSelected: useCallback((courtId, hour) => selectedBlockSlots.some((slot) => slot.courtId === courtId && slot.date === dayKey && slot.hour === hour), [selectedBlockSlots, dayKey]),
		toggleSlot: useCallback((courtId, hour) => {
			const existing = dayOccupancy(courtId, dayKey, bookings, hourSlots, slotStepHours)[hour];
			const court = courts.find((c) => c.id === courtId);
			const slot = {
				courtId,
				court: court === null || court === void 0 ? void 0 : court.name,
				date: dayKey,
				hour
			};
			if (!existing) {
				setSelectedFreeSlots((prev) => prev.some((s) => sameSlot(s, slot)) ? prev.filter((s) => !sameSlot(s, slot)) : [...prev, slot]);
				return;
			}
			if (existing.kind === "block") setSelectedBlockSlots((prev) => prev.some((s) => sameSlot(s, slot)) ? prev.filter((s) => !sameSlot(s, slot)) : [...prev, slot]);
		}, [
			bookings,
			courts,
			dayKey,
			hourSlots,
			setSelectedBlockSlots,
			setSelectedFreeSlots,
			slotStepHours
		])
	};
}
//#endregion
export { useBookingCalendarDaySelection };
