function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
/**
 * 日视图：按 overlay 并行度计算行高、booking overlay 列表、+N 溢出汇总。
 */
import { useMemo } from 'react';
import { dayCourtOverlayRowHeightPx, dayRowHeight, groupRowHeight, DAY_OVERLAY_VISIBLE_BOOKING_CAP } from "../const/bookingCalendarConstants";
import { buildDayRowTopMap, buildOverlayBookings, clusterDayCourtOverlaysByOverlap, dayOverlayHiddenKey, effectiveDayOverlayDisplayLaneCount, maxConcurrentBookingsOnCourt } from "../utils/bookingCalendarDateUtils";
export function useBookingCalendarDayOverlayLayout(visibleCourtRows, dayKey, bookings, hourSlots, slotStepHours) {
  return useMemo(function () {
    var defaultHeights = visibleCourtRows.map(function (row) {
      return row.kind === 'group' ? groupRowHeight : dayRowHeight;
    });
    var tops = buildDayRowTopMap(visibleCourtRows, defaultHeights);
    var overlays = buildOverlayBookings(visibleCourtRows, dayKey, bookings, tops, hourSlots, defaultHeights, slotStepHours);
    var expandedHeights = visibleCourtRows.map(function (row, i) {
      if (row.kind !== 'court') return defaultHeights[i];
      var courtHasOverlay = overlays.some(function (o) {
        return o.courtId === row.id;
      });
      if (!courtHasOverlay) return defaultHeights[i];
      var lc = maxConcurrentBookingsOnCourt(overlays, row.id);
      var displayLc = effectiveDayOverlayDisplayLaneCount(lc);
      return dayCourtOverlayRowHeightPx(displayLc);
    });
    var tops2 = buildDayRowTopMap(visibleCourtRows, expandedHeights);
    overlays = buildOverlayBookings(visibleCourtRows, dayKey, bookings, tops2, hourSlots, expandedHeights, slotStepHours);
    var courtDayDisplayLaneCount = {};
    var hiddenDayOverlayIdSet = new Set();
    var dayOverlayOverflowPluses = [];
    var _iterator = _createForOfIteratorHelper(visibleCourtRows),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var row = _step.value;
        if (row.kind !== 'court') continue;
        var cid = row.id;
        var rawLc = maxConcurrentBookingsOnCourt(overlays, cid);
        courtDayDisplayLaneCount[cid] = effectiveDayOverlayDisplayLaneCount(rawLc);
        var clusters = clusterDayCourtOverlaysByOverlap(overlays, cid);
        var _iterator2 = _createForOfIteratorHelper(clusters),
          _step2;
        try {
          for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
            var cluster = _step2.value;
            if (cluster.length <= DAY_OVERLAY_VISIBLE_BOOKING_CAP) continue;
            var sortedByLane = _toConsumableArray(cluster).sort(function (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 (var i = DAY_OVERLAY_VISIBLE_BOOKING_CAP; i < sortedByLane.length; i++) {
              var o = sortedByLane[i];
              hiddenDayOverlayIdSet.add(dayOverlayHiddenKey(o.item, dayKey, o.courtId));
            }
            var hidden = sortedByLane.slice(DAY_OVERLAY_VISIBLE_BOOKING_CAP);
            var minS = Infinity;
            var maxE = -Infinity;
            var _iterator3 = _createForOfIteratorHelper(cluster),
              _step3;
            try {
              for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
                var _o = _step3.value;
                minS = Math.min(minS, _o.start);
                maxE = Math.max(maxE, _o.start + _o.span);
              }
            } catch (err) {
              _iterator3.e(err);
            } finally {
              _iterator3.f();
            }
            var anchor = hidden[0];
            dayOverlayOverflowPluses.push({
              key: "".concat(cid, "-").concat(minS, "-").concat(maxE, "-").concat(dayKey),
              courtId: cid,
              rowTop: anchor.rowTop,
              rowHeight: anchor.rowHeight,
              start: minS,
              span: maxE - minS,
              plusCount: hidden.length,
              overflowItems: hidden.map(function (o) {
                return o.item;
              })
            });
          }
        } catch (err) {
          _iterator2.e(err);
        } finally {
          _iterator2.f();
        }
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    return {
      dayRowHeights: expandedHeights,
      dayRowTopMap: tops2,
      overlayBookings: overlays,
      courtDayDisplayLaneCount: courtDayDisplayLaneCount,
      hiddenDayOverlayIdSet: hiddenDayOverlayIdSet,
      dayOverlayOverflowPluses: dayOverlayOverflowPluses
    };
  }, [visibleCourtRows, dayKey, bookings, hourSlots, slotStepHours]);
}