import { dayOccupancy, fmtDate, isHourInTimelineSlots } from "../../utils/bookingCalendarDateUtils.js";
import { useMemo } from "react";
//#region src/components/pisellRecordBoard/shellFrame/Calendar/view/resource/useBookingCalendarResourceDayHeaderRemaining.ts
/**
* 资源视图表头：每个自然日列上「营业时段内至少仍有一个空槽」的资源占比。
*/
function useBookingCalendarResourceDayHeaderRemaining(resourceMonthDays, visibleCourts, bookings, hourSlots, slotStepHours) {
	return useMemo(() => {
		const total = visibleCourts.length;
		const map = {};
		for (const d of resourceMonthDays) {
			const dateKey = fmtDate(d);
			const remaining = visibleCourts.filter((court) => hourSlots.some((hour) => {
				if (!isHourInTimelineSlots(hour, hourSlots)) return false;
				return !dayOccupancy(court.id, dateKey, bookings, hourSlots, slotStepHours)[hour];
			})).length;
			map[dateKey] = {
				remaining,
				total,
				ratio: total > 0 ? remaining / total : 0
			};
		}
		return map;
	}, [
		resourceMonthDays,
		visibleCourts,
		bookings,
		hourSlots,
		slotStepHours
	]);
}
//#endregion
export { useBookingCalendarResourceDayHeaderRemaining };
