import { _objectSpread2 } from "../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { OVERFLOW_MODAL_ROW_H } from "../const/bookingCalendarConstants.js";
import { formatHourLabel, getDisplayStatusTag } from "../utils/bookingCalendarDateUtils.js";
import { getBookingStateClasses, getGridBookingRowStateClasses } from "../utils/BookingCalendarStyle.js";
import { statusTagMeta } from "../bookingCalendarViewShared.js";
import React, { useCallback } from "react";
import { FixedSizeList } from "react-window";
import AutoSizer from "react-virtualized-auto-sizer";
//#region src/components/pisellRecordBoard/shellFrame/Calendar/modal/OverflowListModal.tsx
/**
* 溢出预约列表弹层：`FixedSizeList` 虚拟列表；视口宽高由 `AutoSizer` 跟随 flex 剩余区域，
* 列表可视高度取 `min(内容总高, 可用高度)`，避免条数少时底部大块空白。
*/
function OverflowListModalVirtualList({ items, dateKey, onPickItem, onClose, showStatusUi = true }) {
	const Row = useCallback(({ index, style }) => {
		const extraItem = items[index];
		if (!extraItem) return null;
		const displayTag = showStatusUi ? getDisplayStatusTag(extraItem, dateKey) : null;
		const tagMeta = showStatusUi && displayTag ? statusTagMeta(displayTag) : null;
		const rowStateClass = showStatusUi ? getBookingStateClasses(extraItem, dateKey) : getGridBookingRowStateClasses(extraItem);
		return /* @__PURE__ */ React.createElement("div", { style: _objectSpread2(_objectSpread2({}, style), {}, {
			boxSizing: "border-box",
			paddingLeft: 4,
			paddingRight: 4,
			paddingBottom: 8
		}) }, /* @__PURE__ */ React.createElement("button", {
			type: "button",
			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 ${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 ${tagMeta.className} backdrop-blur-[2px]` }, tagMeta.label))));
	}, [
		items,
		dateKey,
		onPickItem,
		onClose,
		showStatusUi
	]);
	if (!(items === null || items === void 0 ? 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, ({ height, width }) => {
		/**
		* flex + max-h 弹层里 AutoSizer 初测常为 0：用常量回退，避免整段 `return null` 空白。
		* 父级列表区已设 min-height，正常情况会得到真实像素。
		*/
		const effH = height >= 1 ? height : 420;
		const effW = width >= 1 ? width : 320;
		const contentHeight = items.length * OVERFLOW_MODAL_ROW_H;
		const 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);
	}));
}
//#endregion
export { OverflowListModalVirtualList };
