function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
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; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
import { FixedSizeList } from 'react-window';
import { OVERFLOW_MODAL_DAY_ROW_H, OVERFLOW_MODAL_LIST_MAX_H, OVERFLOW_MODAL_ROW_GAP, OVERFLOW_MODAL_SIMPLE_ROW_H } from "../const/bookingCalendarConstants";
import { formatHourLabel, formatShortMonthDay, getDisplayStatusTag, getBookingSegmentForDate, isCrossDayBooking } from "../utils/bookingCalendarDateUtils";
import { statusTagMeta } from "../bookingCalendarViewShared";
import { getBookingStateClasses, getGridBookingRowStateClasses } from "../utils/BookingCalendarStyle";
function overflowRowShell(style, children) {
  return /*#__PURE__*/React.createElement("div", {
    style: _objectSpread(_objectSpread({}, style), {}, {
      boxSizing: 'border-box',
      paddingLeft: 4,
      paddingRight: 4,
      paddingBottom: OVERFLOW_MODAL_ROW_GAP
    })
  }, children);
}
function formatOverflowListTimeLine(item, dateKey) {
  var _ref, _seg$startHour, _ref2, _seg$endHour;
  var seg = getBookingSegmentForDate(item, dateKey);
  var startHour = (_ref = (_seg$startHour = seg === null || seg === void 0 ? void 0 : seg.startHour) !== null && _seg$startHour !== void 0 ? _seg$startHour : item.startHour) !== null && _ref !== void 0 ? _ref : 0;
  var endHour = (_ref2 = (_seg$endHour = seg === null || seg === void 0 ? void 0 : seg.endHour) !== null && _seg$endHour !== void 0 ? _seg$endHour : item.endHour) !== null && _ref2 !== void 0 ? _ref2 : startHour;
  if (isCrossDayBooking(item)) {
    var _item$endDate;
    return "".concat(formatShortMonthDay(item.date), " ").concat(formatHourLabel(item.startHour), " - ").concat(formatShortMonthDay((_item$endDate = item.endDate) !== null && _item$endDate !== void 0 ? _item$endDate : item.date), " ").concat(formatHourLabel(item.endHour));
  }
  return "".concat(formatHourLabel(startHour), " - ").concat(formatHourLabel(endHour));
}
function OverflowListRow(_ref3) {
  var index = _ref3.index,
    style = _ref3.style,
    data = _ref3.data;
  var _ref4 = data !== null && data !== void 0 ? data : {},
    listWidth = _ref4.listWidth,
    items = _ref4.items,
    dateKey = _ref4.dateKey,
    onPickItem = _ref4.onPickItem,
    onClose = _ref4.onClose,
    showStatusUi = _ref4.showStatusUi,
    isDayLaneOverflow = _ref4.isDayLaneOverflow,
    isLight = _ref4.isLight,
    renderBooking = _ref4.renderBooking,
    onDragStart = _ref4.onDragStart;
  var extraItem = items === null || items === void 0 ? void 0 : items[index];
  if (!extraItem) return null;
  var handleOpenDetail = function handleOpenDetail(it) {
    onClose();
    onPickItem(it);
  };
  var rowCardH = (isDayLaneOverflow ? OVERFLOW_MODAL_DAY_ROW_H : OVERFLOW_MODAL_SIMPLE_ROW_H) - OVERFLOW_MODAL_ROW_GAP;

  /** 仅日视图 lane 溢出：复用宿主 `renderBooking`（RoomCard） */
  if (isDayLaneOverflow && renderBooking) {
    var _ref5, _seg$startHour2, _ref6, _seg$endHour2, _extraItem$courtId;
    var seg = getBookingSegmentForDate(extraItem, dateKey);
    var startHour = (_ref5 = (_seg$startHour2 = seg === null || seg === void 0 ? void 0 : seg.startHour) !== null && _seg$startHour2 !== void 0 ? _seg$startHour2 : extraItem.startHour) !== null && _ref5 !== void 0 ? _ref5 : 0;
    var endHour = (_ref6 = (_seg$endHour2 = seg === null || seg === void 0 ? void 0 : seg.endHour) !== null && _seg$endHour2 !== void 0 ? _seg$endHour2 : extraItem.endHour) !== null && _ref6 !== void 0 ? _ref6 : startHour;
    var fakeBooking = {
      item: extraItem,
      courtId: String((_extraItem$courtId = extraItem.courtId) !== null && _extraItem$courtId !== void 0 ? _extraItem$courtId : ''),
      start: startHour,
      end: endHour,
      span: Math.max(0, endHour - startHour),
      rowTop: 0,
      rowHeight: rowCardH,
      rowIndex: index,
      continuesPrev: seg === null || seg === void 0 ? void 0 : seg.continuesPrev,
      continuesNext: seg === null || seg === void 0 ? void 0 : seg.continuesNext
    };
    return overflowRowShell(style, /*#__PURE__*/React.createElement("div", {
      className: "relative h-full w-full min-h-0"
    }, renderBooking({
      booking: fakeBooking,
      dayKey: dateKey,
      calendarView: 'day',
      isLight: isLight,
      overlayWidthPx: listWidth,
      onOpenDetail: handleOpenDetail,
      onDragStart: onDragStart !== null && onDragStart !== void 0 ? onDragStart : function () {},
      onJumpNext: function onJumpNext() {}
    })));
  }
  var displayTag = showStatusUi ? getDisplayStatusTag(extraItem, dateKey) : null;
  var tagMeta = showStatusUi && displayTag ? statusTagMeta(displayTag) : null;
  var rowStateClass = showStatusUi ? getBookingStateClasses(extraItem, dateKey) : getGridBookingRowStateClasses(extraItem);
  return overflowRowShell(style, /*#__PURE__*/React.createElement("button", {
    type: "button",
    onClick: function onClick() {
      return handleOpenDetail(extraItem);
    },
    className: "flex h-full min-h-0 w-full min-w-0 flex-col justify-center rounded-lg px-3 py-2 text-left text-xs text-white ".concat(rowStateClass)
  }, /*#__PURE__*/React.createElement("div", {
    className: "min-w-0 truncate font-medium"
  }, extraItem.name), /*#__PURE__*/React.createElement("div", {
    className: "mt-0.5 truncate opacity-80"
  }, formatOverflowListTimeLine(extraItem, dateKey)), tagMeta && /*#__PURE__*/React.createElement("div", {
    className: "mt-1 flex justify-end"
  }, /*#__PURE__*/React.createElement("span", {
    className: "rounded px-1.5 py-px text-[10px] font-semibold leading-tight ".concat(tagMeta.className, " backdrop-blur-[2px]")
  }, tagMeta.label))));
}

/**
 * 溢出预约列表弹层：`FixedSizeList` 虚拟列表。
 * - 日视图 lane +N：宿主 `renderBooking`（RoomCard）
 * - 月 / 周 / 资源 +N：内置列表行（名称 + 时间），不用格内自定义卡片
 */
export function OverflowListModalVirtualList(_ref7) {
  var items = _ref7.items,
    dateKey = _ref7.dateKey,
    onPickItem = _ref7.onPickItem,
    onClose = _ref7.onClose,
    _ref7$showStatusUi = _ref7.showStatusUi,
    showStatusUi = _ref7$showStatusUi === void 0 ? true : _ref7$showStatusUi,
    _ref7$isDayLaneOverfl = _ref7.isDayLaneOverflow,
    isDayLaneOverflow = _ref7$isDayLaneOverfl === void 0 ? false : _ref7$isDayLaneOverfl,
    _ref7$isLight = _ref7.isLight,
    isLight = _ref7$isLight === void 0 ? false : _ref7$isLight,
    renderBooking = _ref7.renderBooking,
    onDragStart = _ref7.onDragStart;
  var listWrapRef = useRef(null);
  var _useState = useState(480),
    _useState2 = _slicedToArray(_useState, 2),
    listWidth = _useState2[0],
    setListWidth = _useState2[1];
  useLayoutEffect(function () {
    var el = listWrapRef.current;
    if (!el) return;
    var measure = function measure() {
      var w = el.clientWidth;
      if (w > 0) setListWidth(w);
    };
    measure();
    var ro = new ResizeObserver(measure);
    ro.observe(el);
    return function () {
      return ro.disconnect();
    };
  }, []);
  var itemData = useMemo(function () {
    return {
      listWidth: listWidth,
      items: items,
      dateKey: dateKey,
      onPickItem: onPickItem,
      onClose: onClose,
      showStatusUi: showStatusUi,
      isDayLaneOverflow: isDayLaneOverflow,
      isLight: isLight,
      renderBooking: renderBooking,
      onDragStart: onDragStart
    };
  }, [listWidth, items, dateKey, onPickItem, onClose, showStatusUi, isDayLaneOverflow, isLight, renderBooking, onDragStart]);
  var Row = useCallback(function (props) {
    return /*#__PURE__*/React.createElement(OverflowListRow, props);
  }, []);
  if (!(items !== null && items !== void 0 && items.length)) return null;
  var rowH = isDayLaneOverflow ? OVERFLOW_MODAL_DAY_ROW_H : OVERFLOW_MODAL_SIMPLE_ROW_H;
  var contentHeight = items.length * rowH;
  var listHeight = Math.max(rowH, Math.min(contentHeight, OVERFLOW_MODAL_LIST_MAX_H));
  return /*#__PURE__*/React.createElement("div", {
    ref: listWrapRef,
    className: "pisell-scroll-hidden w-full touch-pan-y"
  }, /*#__PURE__*/React.createElement(FixedSizeList, {
    height: listHeight,
    itemCount: items.length,
    itemSize: rowH,
    width: "100%",
    itemData: itemData,
    style: {
      overflowX: 'hidden'
    }
  }, Row));
}