import { dayOccupancy } from "../../utils/bookingCalendarDateUtils.js";
import { useMemo } from "react";
//#region src/components/pisellRecordBoard/shellFrame/Calendar/view/day/useBookingCalendarDayHourRemaining.ts
/**
* 日视图表头：每列整点仍空闲资源占比。
*/
function useBookingCalendarDayHourRemaining(visibleCourts, dayKey, bookings, hourSlots, slotStepHours, isBusinessHour) {
	return useMemo(() => {
		const total = visibleCourts.length;
		return Object.fromEntries(hourSlots.map((hour) => {
			if (!isBusinessHour(hour)) return [hour, {
				remaining: 0,
				total,
				ratio: 0
			}];
			const remaining = visibleCourts.filter((court) => !dayOccupancy(court.id, dayKey, bookings, hourSlots, slotStepHours)[hour]).length;
			return [hour, {
				remaining,
				total,
				ratio: total > 0 ? remaining / total : 0
			}];
		}));
	}, [
		visibleCourts,
		dayKey,
		bookings,
		hourSlots,
		slotStepHours,
		isBusinessHour
	]);
}
//#endregion
export { useBookingCalendarDayHourRemaining };
