var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pisellRecordBoard/shellFrame/Calendar/modal/OverflowListModal.tsx
var OverflowListModal_exports = {};
__export(OverflowListModal_exports, {
  OverflowListModalVirtualList: () => OverflowListModalVirtualList
});
module.exports = __toCommonJS(OverflowListModal_exports);
var import_react = __toESM(require("react"));
var import_react_window = require("react-window");
var import_bookingCalendarConstants = require("../const/bookingCalendarConstants");
var import_bookingCalendarDateUtils = require("../utils/bookingCalendarDateUtils");
var import_bookingCalendarViewShared = require("../bookingCalendarViewShared");
var import_BookingCalendarStyle = require("../utils/BookingCalendarStyle");
function overflowRowShell(style, children) {
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        ...style,
        boxSizing: "border-box",
        paddingLeft: 4,
        paddingRight: 4,
        paddingBottom: import_bookingCalendarConstants.OVERFLOW_MODAL_ROW_GAP
      }
    },
    children
  );
}
function formatOverflowListTimeLine(item, dateKey) {
  const seg = (0, import_bookingCalendarDateUtils.getBookingSegmentForDate)(item, dateKey);
  const startHour = (seg == null ? void 0 : seg.startHour) ?? item.startHour ?? 0;
  const endHour = (seg == null ? void 0 : seg.endHour) ?? item.endHour ?? startHour;
  if ((0, import_bookingCalendarDateUtils.isCrossDayBooking)(item)) {
    return `${(0, import_bookingCalendarDateUtils.formatShortMonthDay)(item.date)} ${(0, import_bookingCalendarDateUtils.formatHourLabel)(
      item.startHour
    )} - ${(0, import_bookingCalendarDateUtils.formatShortMonthDay)(item.endDate ?? item.date)} ${(0, import_bookingCalendarDateUtils.formatHourLabel)(
      item.endHour
    )}`;
  }
  return `${(0, import_bookingCalendarDateUtils.formatHourLabel)(startHour)} - ${(0, import_bookingCalendarDateUtils.formatHourLabel)(endHour)}`;
}
function OverflowListRow({
  index,
  style,
  data
}) {
  const {
    listWidth,
    items,
    dateKey,
    onPickItem,
    onClose,
    showStatusUi,
    isDayLaneOverflow,
    isLight,
    renderBooking,
    onDragStart
  } = data ?? {};
  const extraItem = items == null ? void 0 : items[index];
  if (!extraItem) return null;
  const handleOpenDetail = (it) => {
    onClose();
    onPickItem(it);
  };
  const rowCardH = (isDayLaneOverflow ? import_bookingCalendarConstants.OVERFLOW_MODAL_DAY_ROW_H : import_bookingCalendarConstants.OVERFLOW_MODAL_SIMPLE_ROW_H) - import_bookingCalendarConstants.OVERFLOW_MODAL_ROW_GAP;
  if (isDayLaneOverflow && renderBooking) {
    const seg = (0, import_bookingCalendarDateUtils.getBookingSegmentForDate)(extraItem, dateKey);
    const startHour = (seg == null ? void 0 : seg.startHour) ?? extraItem.startHour ?? 0;
    const endHour = (seg == null ? void 0 : seg.endHour) ?? extraItem.endHour ?? startHour;
    const fakeBooking = {
      item: extraItem,
      courtId: String(extraItem.courtId ?? ""),
      start: startHour,
      end: endHour,
      span: Math.max(0, endHour - startHour),
      rowTop: 0,
      rowHeight: rowCardH,
      rowIndex: index,
      continuesPrev: seg == null ? void 0 : seg.continuesPrev,
      continuesNext: seg == null ? void 0 : seg.continuesNext
    };
    return overflowRowShell(
      style,
      /* @__PURE__ */ import_react.default.createElement("div", { className: "relative h-full w-full min-h-0" }, renderBooking({
        booking: fakeBooking,
        dayKey: dateKey,
        calendarView: "day",
        isLight,
        overlayWidthPx: listWidth,
        onOpenDetail: handleOpenDetail,
        onDragStart: onDragStart ?? (() => {
        }),
        onJumpNext: () => {
        }
      }))
    );
  }
  const displayTag = showStatusUi ? (0, import_bookingCalendarDateUtils.getDisplayStatusTag)(extraItem, dateKey) : null;
  const tagMeta = showStatusUi && displayTag ? (0, import_bookingCalendarViewShared.statusTagMeta)(displayTag) : null;
  const rowStateClass = showStatusUi ? (0, import_BookingCalendarStyle.getBookingStateClasses)(extraItem, dateKey) : (0, import_BookingCalendarStyle.getGridBookingRowStateClasses)(extraItem);
  return overflowRowShell(
    style,
    /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        type: "button",
        onClick: () => 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 ${rowStateClass}`
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "min-w-0 truncate font-medium" }, extraItem.name),
      /* @__PURE__ */ import_react.default.createElement("div", { className: "mt-0.5 truncate opacity-80" }, formatOverflowListTimeLine(extraItem, dateKey)),
      tagMeta && /* @__PURE__ */ import_react.default.createElement("div", { className: "mt-1 flex justify-end" }, /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          className: `rounded px-1.5 py-px text-[10px] font-semibold leading-tight ${tagMeta.className} backdrop-blur-[2px]`
        },
        tagMeta.label
      ))
    )
  );
}
function OverflowListModalVirtualList({
  items,
  dateKey,
  onPickItem,
  onClose,
  showStatusUi = true,
  isDayLaneOverflow = false,
  isLight = false,
  renderBooking,
  onDragStart
}) {
  const listWrapRef = (0, import_react.useRef)(null);
  const [listWidth, setListWidth] = (0, import_react.useState)(480);
  (0, import_react.useLayoutEffect)(() => {
    const el = listWrapRef.current;
    if (!el) return;
    const measure = () => {
      const w = el.clientWidth;
      if (w > 0) setListWidth(w);
    };
    measure();
    const ro = new ResizeObserver(measure);
    ro.observe(el);
    return () => ro.disconnect();
  }, []);
  const itemData = (0, import_react.useMemo)(
    () => ({
      listWidth,
      items,
      dateKey,
      onPickItem,
      onClose,
      showStatusUi,
      isDayLaneOverflow,
      isLight,
      renderBooking,
      onDragStart
    }),
    [
      listWidth,
      items,
      dateKey,
      onPickItem,
      onClose,
      showStatusUi,
      isDayLaneOverflow,
      isLight,
      renderBooking,
      onDragStart
    ]
  );
  const Row = (0, import_react.useCallback)(
    (props) => /* @__PURE__ */ import_react.default.createElement(OverflowListRow, { ...props }),
    []
  );
  if (!(items == null ? void 0 : items.length)) return null;
  const rowH = isDayLaneOverflow ? import_bookingCalendarConstants.OVERFLOW_MODAL_DAY_ROW_H : import_bookingCalendarConstants.OVERFLOW_MODAL_SIMPLE_ROW_H;
  const contentHeight = items.length * rowH;
  const listHeight = Math.max(
    rowH,
    Math.min(contentHeight, import_bookingCalendarConstants.OVERFLOW_MODAL_LIST_MAX_H)
  );
  return /* @__PURE__ */ import_react.default.createElement("div", { ref: listWrapRef, className: "pisell-scroll-hidden w-full touch-pan-y" }, /* @__PURE__ */ import_react.default.createElement(
    import_react_window.FixedSizeList,
    {
      height: listHeight,
      itemCount: items.length,
      itemSize: rowH,
      width: "100%",
      itemData,
      style: { overflowX: "hidden" }
    },
    Row
  ));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  OverflowListModalVirtualList
});
