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 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 } from 'react';
import { FixedSizeList } from 'react-window';
import AutoSizer from 'react-virtualized-auto-sizer';
import { OVERFLOW_MODAL_LIST_MAX_H, OVERFLOW_MODAL_ROW_GAP, OVERFLOW_MODAL_ROW_H } from "../const/bookingCalendarConstants";
import { formatHourLabel, getDisplayStatusTag } from "../utils/bookingCalendarDateUtils";
import { statusTagMeta } from "../bookingCalendarViewShared";
import { getBookingStateClasses, getGridBookingRowStateClasses } from "../utils/BookingCalendarStyle";
/**
 * 溢出预约列表弹层：`FixedSizeList` 虚拟列表；视口宽高由 `AutoSizer` 跟随 flex 剩余区域，
 * 列表可视高度取 `min(内容总高, 可用高度)`，避免条数少时底部大块空白。
 */
export function OverflowListModalVirtualList(_ref) {
  var items = _ref.items,
    dateKey = _ref.dateKey,
    onPickItem = _ref.onPickItem,
    onClose = _ref.onClose,
    _ref$showStatusUi = _ref.showStatusUi,
    showStatusUi = _ref$showStatusUi === void 0 ? true : _ref$showStatusUi;
  var Row = useCallback(function (_ref2) {
    var index = _ref2.index,
      style = _ref2.style;
    var extraItem = items[index];
    if (!extraItem) return null;
    var displayTag = showStatusUi ? getDisplayStatusTag(extraItem, dateKey) : null;
    var tagMeta = showStatusUi && displayTag ? statusTagMeta(displayTag) : null;
    var rowStateClass = showStatusUi ? getBookingStateClasses(extraItem, dateKey) : getGridBookingRowStateClasses(extraItem);
    return /*#__PURE__*/React.createElement("div", {
      style: _objectSpread(_objectSpread({}, style), {}, {
        boxSizing: 'border-box',
        paddingLeft: 4,
        paddingRight: 4,
        paddingBottom: OVERFLOW_MODAL_ROW_GAP
      })
    }, /*#__PURE__*/React.createElement("button", {
      type: "button",
      onClick: function onClick() {
        onClose();
        onPickItem(extraItem);
      },
      className: "flex h-full min-h-0 w-full min-w-0 flex-col justify-center rounded-xl px-4 py-3 text-left text-white ".concat(rowStateClass)
    }, /*#__PURE__*/React.createElement("div", {
      className: "min-w-0 break-words font-medium"
    }, extraItem.name), /*#__PURE__*/React.createElement("div", {
      className: "mt-1 text-sm opacity-85"
    }, formatHourLabel(extraItem.startHour), " -", ' ', formatHourLabel(extraItem.endHour)), tagMeta && /*#__PURE__*/React.createElement("div", {
      className: "mt-2 flex justify-end"
    }, /*#__PURE__*/React.createElement("span", {
      className: "rounded-lg px-2 py-0.5 text-[10px] font-semibold ".concat(tagMeta.className, " backdrop-blur-[2px]")
    }, tagMeta.label))));
  }, [items, dateKey, onPickItem, onClose, showStatusUi]);
  if (!(items !== null && items !== void 0 && items.length)) return null;
  return /*#__PURE__*/React.createElement("div", {
    className: "pisell-scroll-hidden flex h-full min-h-0 w-full min-w-0 flex-1 flex-col touch-pan-y"
  }, /*#__PURE__*/React.createElement(AutoSizer, null, function (_ref3) {
    var height = _ref3.height,
      width = _ref3.width;
    /**
     * flex + max-h 弹层里 AutoSizer 初测常为 0：用常量回退，避免整段 `return null` 空白。
     * 父级列表区已设 min-height，正常情况会得到真实像素。
     */
    var effH = height >= 1 ? height : OVERFLOW_MODAL_LIST_MAX_H;
    var effW = width >= 1 ? width : 320;
    var contentHeight = items.length * OVERFLOW_MODAL_ROW_H;
    var listHeight = Math.max(1, Math.min(contentHeight, effH));
    return /*#__PURE__*/React.createElement(FixedSizeList, {
      height: listHeight,
      itemCount: items.length,
      itemSize: OVERFLOW_MODAL_ROW_H,
      width: effW,
      style: {
        overflowX: 'hidden'
      }
    }, Row);
  }));
}