require("../../../../../_virtual/_rolldown/runtime.js");
const require_bookingCalendarConstants = require("../const/bookingCalendarConstants.js");
const require_bookingCalendarDateUtils = require("../utils/bookingCalendarDateUtils.js");
let react = require("react");
//#region src/components/pisellRecordBoard/shellFrame/Calendar/hooks/useBookingCalendarDayOverlayLayout.ts
/**
* 日视图：按 overlay 并行度计算行高、booking overlay 列表、+N 溢出汇总。
*/
function useBookingCalendarDayOverlayLayout(visibleCourtRows, dayKey, bookings, hourSlots, slotStepHours) {
	return (0, react.useMemo)(() => {
		const defaultHeights = visibleCourtRows.map((row) => row.kind === "group" ? 38 : 44);
		let overlays = require_bookingCalendarDateUtils.buildOverlayBookings(visibleCourtRows, dayKey, bookings, require_bookingCalendarDateUtils.buildDayRowTopMap(visibleCourtRows, defaultHeights), hourSlots, defaultHeights, slotStepHours);
		const expandedHeights = visibleCourtRows.map((row, i) => {
			if (row.kind !== "court") return defaultHeights[i];
			if (!overlays.some((o) => o.courtId === row.id)) return defaultHeights[i];
			return require_bookingCalendarConstants.dayCourtOverlayRowHeightPx(require_bookingCalendarDateUtils.effectiveDayOverlayDisplayLaneCount(require_bookingCalendarDateUtils.maxConcurrentBookingsOnCourt(overlays, row.id)));
		});
		const tops2 = require_bookingCalendarDateUtils.buildDayRowTopMap(visibleCourtRows, expandedHeights);
		overlays = require_bookingCalendarDateUtils.buildOverlayBookings(visibleCourtRows, dayKey, bookings, tops2, hourSlots, expandedHeights, slotStepHours);
		const courtDayDisplayLaneCount = {};
		const hiddenDayOverlayIdSet = /* @__PURE__ */ new Set();
		const dayOverlayOverflowPluses = [];
		for (const row of visibleCourtRows) {
			if (row.kind !== "court") continue;
			const cid = row.id;
			courtDayDisplayLaneCount[cid] = require_bookingCalendarDateUtils.effectiveDayOverlayDisplayLaneCount(require_bookingCalendarDateUtils.maxConcurrentBookingsOnCourt(overlays, cid));
			const clusters = require_bookingCalendarDateUtils.clusterDayCourtOverlaysByOverlap(overlays, cid);
			for (const cluster of clusters) {
				if (cluster.length <= 3) continue;
				const sortedByLane = [...cluster].sort((a, b) => {
					var _a$lane, _b$lane;
					return ((_a$lane = a.lane) !== null && _a$lane !== void 0 ? _a$lane : 0) - ((_b$lane = b.lane) !== null && _b$lane !== void 0 ? _b$lane : 0) || a.start - b.start;
				});
				for (let i = 3; i < sortedByLane.length; i++) {
					const o = sortedByLane[i];
					hiddenDayOverlayIdSet.add(require_bookingCalendarDateUtils.dayOverlayHiddenKey(o.item, dayKey, o.courtId));
				}
				const hidden = sortedByLane.slice(3);
				let minS = Infinity;
				let maxE = -Infinity;
				for (const o of cluster) {
					minS = Math.min(minS, o.start);
					maxE = Math.max(maxE, o.start + o.span);
				}
				const anchor = hidden[0];
				dayOverlayOverflowPluses.push({
					key: `${cid}-${minS}-${maxE}-${dayKey}`,
					courtId: cid,
					rowTop: anchor.rowTop,
					rowHeight: anchor.rowHeight,
					start: minS,
					span: maxE - minS,
					plusCount: hidden.length,
					overflowItems: hidden.map((o) => o.item)
				});
			}
		}
		return {
			dayRowHeights: expandedHeights,
			dayRowTopMap: tops2,
			overlayBookings: overlays,
			courtDayDisplayLaneCount,
			hiddenDayOverlayIdSet,
			dayOverlayOverflowPluses
		};
	}, [
		visibleCourtRows,
		dayKey,
		bookings,
		hourSlots,
		slotStepHours
	]);
}
//#endregion
exports.useBookingCalendarDayOverlayLayout = useBookingCalendarDayOverlayLayout;
