var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pisellRecordBoard/shellFrame/Calendar/hooks/useBookingCalendarDayOverlayLayout.ts
var useBookingCalendarDayOverlayLayout_exports = {};
__export(useBookingCalendarDayOverlayLayout_exports, {
  useBookingCalendarDayOverlayLayout: () => useBookingCalendarDayOverlayLayout
});
module.exports = __toCommonJS(useBookingCalendarDayOverlayLayout_exports);
var import_react = require("react");
var import_bookingCalendarConstants = require("../const/bookingCalendarConstants");
var import_bookingCalendarDateUtils = require("../utils/bookingCalendarDateUtils");
function useBookingCalendarDayOverlayLayout(visibleCourtRows, dayKey, bookings, hourSlots, slotStepHours) {
  return (0, import_react.useMemo)(() => {
    const defaultHeights = visibleCourtRows.map(
      (row) => row.kind === "group" ? import_bookingCalendarConstants.groupRowHeight : import_bookingCalendarConstants.dayRowHeight
    );
    let tops = (0, import_bookingCalendarDateUtils.buildDayRowTopMap)(visibleCourtRows, defaultHeights);
    let overlays = (0, import_bookingCalendarDateUtils.buildOverlayBookings)(
      visibleCourtRows,
      dayKey,
      bookings,
      tops,
      hourSlots,
      defaultHeights,
      slotStepHours
    );
    const expandedHeights = visibleCourtRows.map(
      (row, i) => {
        if (row.kind !== "court") return defaultHeights[i];
        const courtHasOverlay = overlays.some((o) => o.courtId === row.id);
        if (!courtHasOverlay) return defaultHeights[i];
        const lc = (0, import_bookingCalendarDateUtils.maxConcurrentBookingsOnCourt)(overlays, row.id);
        const displayLc = (0, import_bookingCalendarDateUtils.effectiveDayOverlayDisplayLaneCount)(lc);
        return (0, import_bookingCalendarConstants.dayCourtOverlayRowHeightPx)(displayLc);
      }
    );
    const tops2 = (0, import_bookingCalendarDateUtils.buildDayRowTopMap)(visibleCourtRows, expandedHeights);
    overlays = (0, import_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;
      const rawLc = (0, import_bookingCalendarDateUtils.maxConcurrentBookingsOnCourt)(overlays, cid);
      courtDayDisplayLaneCount[cid] = (0, import_bookingCalendarDateUtils.effectiveDayOverlayDisplayLaneCount)(rawLc);
      const clusters = (0, import_bookingCalendarDateUtils.clusterDayCourtOverlaysByOverlap)(overlays, cid);
      for (const cluster of clusters) {
        if (cluster.length <= import_bookingCalendarConstants.DAY_OVERLAY_VISIBLE_BOOKING_CAP) continue;
        const sortedByLane = [...cluster].sort(
          (a, b) => (a.lane ?? 0) - (b.lane ?? 0) || a.start - b.start
        );
        for (let i = import_bookingCalendarConstants.DAY_OVERLAY_VISIBLE_BOOKING_CAP; i < sortedByLane.length; i++) {
          const o = sortedByLane[i];
          hiddenDayOverlayIdSet.add(
            (0, import_bookingCalendarDateUtils.dayOverlayHiddenKey)(o.item, dayKey, o.courtId)
          );
        }
        const hidden = sortedByLane.slice(import_bookingCalendarConstants.DAY_OVERLAY_VISIBLE_BOOKING_CAP);
        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]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useBookingCalendarDayOverlayLayout
});
