const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_objectWithoutProperties = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_useEngineContext = require("../../hooks/useEngineContext.js");
const require_index = require("../../utils/index.js");
const require_serve = require("../pisellSalesManagement/serve.js");
const require_ReservationBookingDetailModal = require("./components/bookingDetailModal/ReservationBookingDetailModal.js");
const require_floorPlanApi = require("./floorMap/floorPlanApi.js");
const require_reservationCards = require("./floorMap/reservationCards.js");
const require_ReservationFloorMapHud = require("./floorMap/ReservationFloorMapHud.js");
const require_reservationHudTableRows = require("./floorMap/reservationHudTableRows.js");
const require_useBookingPerspective = require("../pisellSalesManagement/hooks/useBookingPerspective.js");
const require_usePisellReservationBookingData = require("./hooks/usePisellReservationBookingData.js");
const require_usePisellReservationResourceTableData = require("./hooks/usePisellReservationResourceTableData.js");
const require_reservationConstants = require("./reservationConstants.js");
const require_reservationDensity = require("./data/reservationDensity.js");
const require_bookingToReservationTables = require("./data/bookingToReservationTables.js");
const require_reservationDataUtils = require("./data/reservationDataUtils.js");
const require_hudDrawerLocalListQuery = require("./data/hudDrawerLocalListQuery.js");
const require_reservationTablesMerge = require("./data/reservationTablesMerge.js");
const require_floorMapBoundRecordIds = require("./floorMap/floorMapBoundRecordIds.js");
const require_PisellReservationSubcomponents = require("./components/PisellReservationSubcomponents.js");
const require_useReservationFloorPlan = require("./floorMap/useReservationFloorPlan.js");
const require_useReservationFloorMapMerged = require("./floorMap/useReservationFloorMapMerged.js");
const require_useReservationScheduleDebounced = require("./hooks/useReservationScheduleDebounced.js");
const require_useReservationSalesHostData = require("./hooks/useReservationSalesHostData.js");
const require_useNewReservationRoutesFromEngine = require("./hooks/useNewReservationRoutesFromEngine.js");
const require_useReservationLoadingShownDebounced = require("./hooks/useReservationLoadingShownDebounced.js");
const require_useFloorMapBookingInteraction = require("./hooks/useFloorMapBookingInteraction.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let ahooks = require("ahooks");
require("dayjs/locale/zh-cn");
require("dayjs/locale/en");
require("dayjs/locale/zh-tw");
let _pisell_date_picker = require("@pisell/date-picker");
let _pisell_date_picker_es_AdapterDayjs = require("@pisell/date-picker/es/AdapterDayjs");
require("./PisellReservation.less");
//#region src/plus/pisellReservation/PisellReservation.tsx
const _excluded = [
	"gridDataSourceKey",
	"dataSources",
	"scheduleValue",
	"onScheduleChange",
	"toolBar",
	"floorMap",
	"scheduleStartSlot",
	"scheduleEndSlot",
	"onNewReservation",
	"timeNavigatorProps",
	"scheduleProps",
	"fab",
	"defaultBodyView",
	"data",
	"total",
	"pagination",
	"onPageChange",
	"onSearch",
	"onReset",
	"searchParams",
	"loading",
	"rowKey",
	"className",
	"style",
	"floorPlanId",
	"floorPlanCanvasWidth",
	"floorPlanCanvasHeight",
	"floorPlanCode",
	"floorPlanName",
	"floorPlanSort",
	"floorPlanStatus",
	"onFloorPlanPersisted",
	"putFloorPlan",
	"onFloorMapBookingClick",
	"bodyViewSwitchable",
	"lockedBodyView",
	"bodyViewStorageKey",
	"floorMapHudTableDrawer"
], _excluded2 = [
	"tabs",
	"topRight",
	"bottomLeft"
];
/**
* 场控：仅把平面图 items 同步到父级，视口内不渲染独立 HUD（统计在固定抽屉标题栏）。
*/
function ReservationHudMapItemsSync({ items, setItems }) {
	(0, react.useEffect)(() => {
		setItems(items);
	}, [items, setItems]);
	return null;
}
/**
* 预约看板 Core：内置 Sales 预约列表 + 时间轴 + 平面图。
* 页面壳 {@link PisellReservationBookingPage} / {@link PisellVenueControlPage} 通过 props 组合默认行为。
*/
const PisellReservationCore = (props) => {
	var _engineCtx$engine, _engineCtx$appHelper, _engineCtx$appHelper$, _app$router, _app$router$getRoutes, _engineCtx$appHelper3, _floorMapProp$mode, _timeNavigatorPropsPr2, _timeNavigatorPropsPr3, _scroll$autoCalc, _scroll;
	const { gridDataSourceKey = require_reservationConstants.GRID_DS_KEY, dataSources: dataSourcesProp, scheduleValue: scheduleValueProp, onScheduleChange, toolBar: toolBarProp, floorMap: floorMapProp, scheduleStartSlot: scheduleStartSlotProp, scheduleEndSlot: scheduleEndSlotProp, onNewReservation, timeNavigatorProps: timeNavigatorPropsProp, scheduleProps: schedulePropsProp, fab, defaultBodyView: _unusedDefaultBodyView, data: dataProp, total: totalProp, pagination: paginationProp, onPageChange: onPageChangeProp, onSearch: onSearchProp, onReset: onResetProp, searchParams: searchParamsProp, loading: loadingProp, rowKey = "id", className, style, floorPlanId: floorPlanIdProp, floorPlanCanvasWidth, floorPlanCanvasHeight, floorPlanCode, floorPlanName, floorPlanSort, floorPlanStatus, onFloorPlanPersisted, putFloorPlan, onFloorMapBookingClick, bodyViewSwitchable = true, lockedBodyView, bodyViewStorageKey, floorMapHudTableDrawer = false } = props, rest = require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
	const hudItemsRef = (0, react.useRef)([]);
	const [hudMapItems, setHudMapItems] = (0, react.useState)([]);
	const [hudDrawerOpen, setHudDrawerOpen] = (0, react.useState)(false);
	/** HUD 抽屉：当前画布绑定资源 id，用于在 floorDayBooking 列表上二次过滤展示 */
	const [hudDrawerResourceIds, setHudDrawerResourceIds] = (0, react.useState)(null);
	/** 抽屉内 RecordBoard：与打开瞬间父级筛参快照一致，后续 onSearch 仅改本地不露父级请求 */
	const [hudDrawerLocalSearchParams, setHudDrawerLocalSearchParams] = (0, react.useState)({});
	const hudDrawerSearchParamsOpenSnapshotRef = (0, react.useRef)({});
	/** HUD 表格：对已过滤全量行做客户端切片分页（与主表 HTTP 分页无关） */
	const [hudDrawerListPagination, setHudDrawerListPagination] = (0, react.useState)({
		pageNumber: 1,
		pageSize: 50
	});
	const isInternalListData = require_reservationDataUtils.shouldUseBuiltinReservationList(dataProp, totalProp, paginationProp, onPageChangeProp);
	const resolvedFloorPlanId = floorPlanIdProp === null ? null : floorPlanIdProp === void 0 ? 1 : floorPlanIdProp;
	const effectiveFloorPlanCode = floorPlanCode !== null && floorPlanCode !== void 0 ? floorPlanCode : require_floorPlanApi.PISELL_RESERVATION_FLOOR_PLAN_CODE;
	const engineCtx = require_useEngineContext.default();
	const pisellos = require_useEngineContext.usePisellOS();
	/** 低代码里 context 常每次给新 `pisellos` 对象，勿把 `pisellos` 放进 effect 依赖 */
	const pisellosRef = (0, react.useRef)(pisellos);
	pisellosRef.current = pisellos;
	const hasPisellosGetModule = typeof (pisellos === null || pisellos === void 0 ? void 0 : pisellos.getModule) === "function";
	const engineLocale = (engineCtx === null || engineCtx === void 0 || (_engineCtx$engine = engineCtx.engine) === null || _engineCtx$engine === void 0 || (_engineCtx$engine = _engineCtx$engine.props) === null || _engineCtx$engine === void 0 ? void 0 : _engineCtx$engine.locale) || "zh-CN";
	const app = engineCtx === null || engineCtx === void 0 || (_engineCtx$appHelper = engineCtx.appHelper) === null || _engineCtx$appHelper === void 0 || (_engineCtx$appHelper = _engineCtx$appHelper.utils) === null || _engineCtx$appHelper === void 0 || (_engineCtx$appHelper$ = _engineCtx$appHelper.getApp) === null || _engineCtx$appHelper$ === void 0 ? void 0 : _engineCtx$appHelper$.call(_engineCtx$appHelper);
	const router = app === null || app === void 0 || (_app$router = app.router) === null || _app$router === void 0 || (_app$router$getRoutes = _app$router.getRoutes) === null || _app$router$getRoutes === void 0 ? void 0 : _app$router$getRoutes.call(_app$router);
	const muiDatePickerAdapterLocale = (0, react.useMemo)(() => {
		const loc = String(engineLocale).toLowerCase();
		if (loc.startsWith("zh-cn")) return "zh-cn";
		if (loc.startsWith("zh-tw") || loc.startsWith("zh-hk")) return "zh-tw";
		return "en";
	}, [engineLocale]);
	(0, react.useEffect)(() => {
		var _engineCtx$appHelper2;
		const r = engineCtx === null || engineCtx === void 0 || (_engineCtx$appHelper2 = engineCtx.appHelper) === null || _engineCtx$appHelper2 === void 0 || (_engineCtx$appHelper2 = _engineCtx$appHelper2.utils) === null || _engineCtx$appHelper2 === void 0 ? void 0 : _engineCtx$appHelper2.request;
		if (r) require_index.request.setRequest(r);
	}, [engineCtx === null || engineCtx === void 0 || (_engineCtx$appHelper3 = engineCtx.appHelper) === null || _engineCtx$appHelper3 === void 0 || (_engineCtx$appHelper3 = _engineCtx$appHelper3.utils) === null || _engineCtx$appHelper3 === void 0 ? void 0 : _engineCtx$appHelper3.request]);
	_pisell_utils.locales.init(require_reservationConstants.PISELL_RESERVATION_PAGE_LOCALES, engineLocale);
	const resourceBoardData = require_usePisellReservationResourceTableData.usePisellReservationResourceTableData(isInternalListData);
	const gridBookingData = require_usePisellReservationBookingData.usePisellReservationBookingData(isInternalListData, {
		listPageSize: 50,
		getInitialSearchParams: require_usePisellReservationBookingData.getGridTableBookingSearchParams,
		subscribeRealtimePush: true
	});
	const { baseFloorConfig, floorPlanRemoteId, setRemoteFloorPlanView } = require_useReservationFloorPlan.useReservationFloorPlan({
		resolvedFloorPlanId,
		effectiveFloorPlanCode,
		gridDataSourceKey,
		floorMapConfigFromProp: floorMapProp === null || floorMapProp === void 0 ? void 0 : floorMapProp.floorMapConfig,
		engineLocale
	});
	/** 与 `useReservationFloorMapMerged` 一致：受控 prop 覆盖远程合并后的 base */
	const floorConfigForBindings = (0, react.useMemo)(() => {
		var _floorMapProp$floorMa;
		return (_floorMapProp$floorMa = floorMapProp === null || floorMapProp === void 0 ? void 0 : floorMapProp.floorMapConfig) !== null && _floorMapProp$floorMa !== void 0 ? _floorMapProp$floorMa : baseFloorConfig;
	}, [floorMapProp === null || floorMapProp === void 0 ? void 0 : floorMapProp.floorMapConfig, baseFloorConfig]);
	const floorBoundFormRecordIds = (0, react.useMemo)(() => require_floorMapBoundRecordIds.sceneElementsToBoundFormRecordIds(floorConfigForBindings.sceneElements, gridDataSourceKey), [floorConfigForBindings.sceneElements, gridDataSourceKey]);
	const floorDayBookingData = require_usePisellReservationBookingData.usePisellReservationBookingData(isInternalListData && !resourceBoardData.loading, {
		listPageSize: 999,
		extraRequestParams: (0, react.useMemo)(() => ({ form_record_ids: floorBoundFormRecordIds }), [floorBoundFormRecordIds])
	});
	const _getRelationTables = (0, ahooks.useRequest)(require_serve.getRelationTables);
	const bookingPerspective = require_useBookingPerspective.useBookingPerspective((0, react.useMemo)(() => ({ relationTables: _getRelationTables.data }), [_getRelationTables.data]));
	const runtimeContext = (0, react.useMemo)(() => ({
		refresh: () => {
			resourceBoardData.refresh();
			gridBookingData.refresh();
			floorDayBookingData.refresh();
		},
		refreshAsync: function() {
			var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
				yield Promise.all([
					resourceBoardData.refreshAsync(),
					gridBookingData.refreshAsync(),
					floorDayBookingData.refreshAsync()
				]);
			});
			return function refreshAsync() {
				return _ref.apply(this, arguments);
			};
		}(),
		currentPerspective: "monitor"
	}), [
		resourceBoardData.refresh,
		resourceBoardData.refreshAsync,
		gridBookingData.refresh,
		gridBookingData.refreshAsync,
		floorDayBookingData.refresh,
		floorDayBookingData.refreshAsync
	]);
	const bookingChildProps = (0, react.useMemo)(() => {
		const build = bookingPerspective.getChildComponentProps;
		return build ? build(runtimeContext) : {};
	}, [bookingPerspective, runtimeContext]);
	const { internalSchedule, setInternalSchedule, schedule, debouncedSchedule, flushCommittedSchedule, queueCommittedSchedule } = require_useReservationScheduleDebounced.useReservationScheduleDebounced({ scheduleValueProp });
	/** 上一次「防抖落定」的日历日，用于仅在换日时 patch floorDayBooking 的 booking 时间窗口 */
	const prevCommittedDateRef = (0, react.useRef)(null);
	const { salesResourceBookings, salesTimelineHighlights } = require_useReservationSalesHostData.useReservationSalesHostData({
		isInternalListData,
		pisellosRef,
		hasPisellosGetModule,
		debouncedSchedule,
		resourceBoardLoading: resourceBoardData.loading,
		floorDayBookingLoading: floorDayBookingData.loading,
		floorDayBookingData: floorDayBookingData.data,
		scheduleDate: schedule.date,
		timeNavigatorPropsProp
	});
	/** 合并资源行 + 当日预约 + 可选宿主游标列表；平面图 renderItem 与表格共用同一 dataSources */
	const tables = (0, react.useMemo)(() => require_reservationTablesMerge.buildReservationMergedTableRows({
		dataSourcesProp,
		gridDataSourceKey,
		isInternalListData,
		resourceList: resourceBoardData.data,
		floorDayBookingList: floorDayBookingData.data,
		schedule,
		dataProp,
		salesResourceBookings
	}), [
		dataSourcesProp,
		gridDataSourceKey,
		isInternalListData,
		resourceBoardData.data,
		floorDayBookingData.data,
		salesResourceBookings,
		(0, dayjs.default)(schedule.date).isValid() ? (0, dayjs.default)(schedule.date).startOf("day").valueOf() : 0,
		schedule.at != null && (0, dayjs.default)(schedule.at).isValid() ? (0, dayjs.default)(schedule.at).valueOf() : 0,
		dataProp
	]);
	/** 顶栏日程防抖落定后的时间键，避免 dayjs 引用抖动 */
	const debouncedScheduleKey = (0, react.useMemo)(() => `${(0, dayjs.default)(debouncedSchedule.date).startOf("day").valueOf()}_${(0, dayjs.default)(debouncedSchedule.at).valueOf()}`, [debouncedSchedule.date, debouncedSchedule.at]);
	/** 调试：切换时间（防抖落定）后，打印当前用于展示的预约相关数据（含接口返回后的更新） */
	(0, react.useEffect)(() => {
		if (!(0, dayjs.default)(debouncedSchedule.date).isValid() || !(0, dayjs.default)(debouncedSchedule.at).isValid()) return;
		console.log("[PisellReservation] 当前日程下的展示数据", {
			debouncedScheduleKey,
			reservationDate: debouncedSchedule.date.toISOString(),
			reservationAt: debouncedSchedule.at.toISOString(),
			isInternalListData,
			gridBookingLoading: isInternalListData ? gridBookingData.loading : void 0,
			floorDayBookingLoading: isInternalListData ? floorDayBookingData.loading : void 0,
			gridBookingList: isInternalListData ? gridBookingData.data : void 0,
			floorDayBookingList: isInternalListData ? floorDayBookingData.data : void 0,
			mergedTableRows: tables,
			externalControlledData: !isInternalListData ? dataProp : void 0
		});
	}, [
		debouncedScheduleKey,
		debouncedSchedule.date,
		debouncedSchedule.at,
		isInternalListData,
		gridBookingData.data,
		gridBookingData.loading,
		floorDayBookingData.data,
		floorDayBookingData.loading,
		tables,
		dataProp
	]);
	const bodyViewRef = (0, react.useRef)(require_reservationDataUtils.readBodyViewFromStorageKey(bodyViewStorageKey));
	const floorMapLayoutRef = (0, react.useRef)(null);
	const [followWallClock, setFollowWallClock] = (0, react.useState)(true);
	const [isNewReservationModalOpen, setIsNewReservationModalOpen] = (0, react.useState)(false);
	const newReservationRoutes = require_useNewReservationRoutesFromEngine.useNewReservationRoutesFromEngine(router);
	const searchParamsRefControlled = (0, react.useRef)(searchParamsProp);
	(0, react.useEffect)(() => {
		searchParamsRefControlled.current = searchParamsProp;
	}, [searchParamsProp]);
	const onSearchRef = (0, react.useRef)(onSearchProp);
	const onScheduleChangeRef = (0, react.useRef)(onScheduleChange);
	/** 每帧同步，供 interval / effect 内调用最新 onSearch、onScheduleChange，避免闭包陈旧 */
	(0, react.useEffect)(() => {
		onSearchRef.current = onSearchProp;
		onScheduleChangeRef.current = onScheduleChange;
	});
	/**
	* `debouncedSchedule` 更新后执行（用户停手约 300ms 或 flush）：
	* - 内置列表：换日历日则更新 floorDayBooking 的 booking_time 窗口；
	* - 外部 data + 当前 bodyView 为平面图：把 reservationDate/At 透传给外部 onSearch。
	*/
	(0, react.useEffect)(() => {
		if (isInternalListData) {
			const d = debouncedSchedule.date;
			const prev = prevCommittedDateRef.current;
			if (prev != null) {
				if (!d.startOf("day").isSame(prev.startOf("day"), "day")) floorDayBookingData.patchSearchParams((prevParams) => require_reservationDataUtils.mergeSearchParamsBookingWindow(prevParams, d));
			}
			prevCommittedDateRef.current = d;
		}
		if (bodyViewRef.current === "floorMap" && !isInternalListData) {
			var _onSearchRef$current, _searchParamsRefContr;
			(_onSearchRef$current = onSearchRef.current) === null || _onSearchRef$current === void 0 || _onSearchRef$current.call(onSearchRef, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, (_searchParamsRefContr = searchParamsRefControlled.current) !== null && _searchParamsRefContr !== void 0 ? _searchParamsRefContr : {}), {}, {
				reservationDate: debouncedSchedule.date.toISOString(),
				reservationAt: debouncedSchedule.at.toISOString()
			}));
		}
	}, [
		debouncedSchedule,
		isInternalListData,
		floorDayBookingData.patchSearchParams
	]);
	const handleScheduleChange = (0, react.useCallback)((next) => {
		setFollowWallClock(false);
		if (scheduleValueProp === void 0) setInternalSchedule(next);
		onScheduleChange === null || onScheduleChange === void 0 || onScheduleChange(next);
		queueCommittedSchedule(next);
	}, [
		scheduleValueProp,
		onScheduleChange,
		setFollowWallClock,
		queueCommittedSchedule
	]);
	/** 先展开外部 dataSources，再用合并后的 `tables` 覆盖同名 key，避免低代码默认的 `tables: []` 盖掉 resource+booking 合并结果 */
	const dataSources = (0, react.useMemo)(() => {
		return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, dataSourcesProp), {}, { [gridDataSourceKey]: tables });
	}, [
		gridDataSourceKey,
		tables,
		dataSourcesProp
	]);
	const showVenueHudDock = (0, react.useMemo)(() => floorMapHudTableDrawer && (hudDrawerOpen || require_ReservationFloorMapHud.reservationFloorMapHudSeatStatsTotal(hudMapItems, dataSources) > 0), [
		floorMapHudTableDrawer,
		hudDrawerOpen,
		hudMapItems,
		dataSources
	]);
	const handleOpenHudTableDrawer = (0, react.useCallback)(() => {
		const boundTableRows = require_reservationHudTableRows.filterReservationRowsBoundOnCanvas(hudItemsRef.current, dataSources, gridDataSourceKey);
		const resourceIdSet = new Set(boundTableRows.map((r) => String(r.id)).filter(Boolean));
		const parentSnapshot = require_hudDrawerLocalListQuery.cloneHudDrawerSearchParams(isInternalListData ? floorDayBookingData.searchParams : searchParamsProp !== null && searchParamsProp !== void 0 ? searchParamsProp : {});
		require_hudDrawerLocalListQuery.stripHudDrawerBookingDateQuickFilter(parentSnapshot);
		hudDrawerSearchParamsOpenSnapshotRef.current = parentSnapshot;
		setHudDrawerLocalSearchParams(parentSnapshot);
		setHudDrawerResourceIds(resourceIdSet);
		setHudDrawerListPagination({
			pageNumber: 1,
			pageSize: 50
		});
		setHudDrawerOpen(true);
	}, [
		dataSources,
		gridDataSourceKey,
		isInternalListData,
		floorDayBookingData.searchParams,
		searchParamsProp
	]);
	const closeHudTableDrawer = (0, react.useCallback)(() => {
		setHudDrawerOpen(false);
		setHudDrawerResourceIds(null);
		setHudDrawerLocalSearchParams({});
		setHudDrawerListPagination({
			pageNumber: 1,
			pageSize: 50
		});
	}, []);
	(0, react.useEffect)(() => {
		if (!floorMapHudTableDrawer || !hudDrawerOpen) return;
		const onKeyDown = (e) => {
			if (e.key === "Escape") closeHudTableDrawer();
		};
		window.addEventListener("keydown", onKeyDown);
		return () => window.removeEventListener("keydown", onKeyDown);
	}, [
		floorMapHudTableDrawer,
		hudDrawerOpen,
		closeHudTableDrawer
	]);
	/**
	* 数据仍来自父级 floorDayBooking / 受控 data（随接口更新）；画布资源子集后再做抽屉本地 keyword/filter/sort。
	*/
	const hudDrawerDisplayRows = (0, react.useMemo)(() => {
		if (!floorMapHudTableDrawer || !hudDrawerOpen || !hudDrawerResourceIds || hudDrawerResourceIds.size === 0) return [];
		return require_hudDrawerLocalListQuery.applyHudDrawerLocalListQuery(require_bookingToReservationTables.filterBookingsByResourceIds(isInternalListData ? floorDayBookingData.data : dataProp !== null && dataProp !== void 0 ? dataProp : [], hudDrawerResourceIds), hudDrawerLocalSearchParams);
	}, [
		floorMapHudTableDrawer,
		hudDrawerOpen,
		hudDrawerResourceIds,
		isInternalListData,
		floorDayBookingData.data,
		dataProp,
		hudDrawerLocalSearchParams
	]);
	const hudDrawerFilteredTotal = hudDrawerDisplayRows.length;
	const hudDrawerMaxPage = Math.max(1, Math.ceil(hudDrawerFilteredTotal / hudDrawerListPagination.pageSize) || 1);
	/** 过滤后条数变少时，避免当前页超出末页 */
	(0, react.useEffect)(() => {
		if (hudDrawerListPagination.pageNumber <= hudDrawerMaxPage) return;
		setHudDrawerListPagination((p) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, p), {}, { pageNumber: hudDrawerMaxPage }));
	}, [hudDrawerMaxPage, hudDrawerListPagination.pageNumber]);
	const hudDrawerPagedRows = (0, react.useMemo)(() => {
		const { pageNumber, pageSize } = hudDrawerListPagination;
		const start = (pageNumber - 1) * pageSize;
		return hudDrawerDisplayRows.slice(start, start + pageSize);
	}, [hudDrawerDisplayRows, hudDrawerListPagination]);
	const hudDrawerToolBar = (0, react.useMemo)(() => {
		const raw = bookingChildProps.toolBar;
		const base = raw != null && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
		const baseClass = "className" in base && typeof base.className === "string" ? base.className : void 0;
		return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, base), {}, {
			toolbarDensity: "compact",
			quickFilter: false,
			className: (0, classnames.default)(baseClass, "pisell-record-board-toolbar--narrow-stack")
		});
	}, [bookingChildProps.toolBar]);
	const hudDrawerLoading = isInternalListData ? floorDayBookingData.loading : loadingProp !== null && loadingProp !== void 0 ? loadingProp : false;
	const hudDrawerBookingPagination = (0, react.useMemo)(() => ({
		pageNumber: hudDrawerListPagination.pageNumber,
		pageSize: hudDrawerListPagination.pageSize
	}), [hudDrawerListPagination.pageNumber, hudDrawerListPagination.pageSize]);
	const hudDrawerOnSearch = (0, react.useCallback)((params) => {
		setHudDrawerListPagination((p) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, p), {}, { pageNumber: 1 }));
		setHudDrawerLocalSearchParams((prev) => require_hudDrawerLocalListQuery.mergeHudDrawerSearchParams(prev, params));
	}, []);
	const hudDrawerOnReset = (0, react.useCallback)(() => {
		setHudDrawerListPagination((p) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, p), {}, { pageNumber: 1 }));
		setHudDrawerLocalSearchParams(require_hudDrawerLocalListQuery.cloneHudDrawerSearchParams(hudDrawerSearchParamsOpenSnapshotRef.current));
	}, []);
	const hudDrawerOnPageChange = (0, react.useCallback)((pageNumber, pageSize) => {
		setHudDrawerListPagination({
			pageNumber,
			pageSize
		});
	}, []);
	/** antd 分页默认不展示「每页条数」；HUD 为本地切片，需显式开启 */
	const hudRecordBoardPaginationConfig = (0, react.useMemo)(() => ({
		showSizeChanger: true,
		pageSizeOptions: [
			"10",
			"20",
			"50",
			"100"
		]
	}), []);
	const renderItemByKind = (0, react.useMemo)(() => require_reservationCards.getReservationRenderItemByKind(dataSources), [dataSources]);
	const reservationFloorMapViewportOverlay = (0, react.useCallback)((args) => {
		const items = args.items;
		hudItemsRef.current = items;
		if (floorMapHudTableDrawer) return /* @__PURE__ */ react.default.createElement(ReservationHudMapItemsSync, {
			items,
			setItems: setHudMapItems
		});
		return /* @__PURE__ */ react.default.createElement(require_ReservationFloorMapHud.ReservationFloorMapHud, {
			items,
			dataSources: args.dataSources,
			interactive: false
		});
	}, [floorMapHudTableDrawer]);
	const isFloorModeControlled = (floorMapProp === null || floorMapProp === void 0 ? void 0 : floorMapProp.mode) !== void 0;
	const [mapEditInternal, setMapEditInternal] = (0, react.useState)(false);
	const effectiveMapMode = (_floorMapProp$mode = floorMapProp === null || floorMapProp === void 0 ? void 0 : floorMapProp.mode) !== null && _floorMapProp$mode !== void 0 ? _floorMapProp$mode : mapEditInternal ? "edit" : "read";
	const { bookingDetailOpen, bookingDetailRaw, bookingDetailRow, bookingDetailSceneName, closeBookingDetailModal, floorMapItemClickBefore } = require_useFloorMapBookingInteraction.useFloorMapBookingInteraction({
		engineCtx,
		onFloorMapBookingClick
	});
	const floorMapMerged = require_useReservationFloorMapMerged.useReservationFloorMapMerged({
		floorMapProp,
		baseFloorConfig,
		dataSources,
		renderItemByKind,
		gridDataSourceKey,
		effectiveMapMode,
		resolvedFloorPlanId,
		floorPlanRemoteId,
		effectiveFloorPlanCode,
		floorPlanCanvasWidth,
		floorPlanCanvasHeight,
		floorPlanName,
		floorPlanSort,
		floorPlanStatus,
		onFloorPlanPersisted,
		putFloorPlan,
		isFloorModeControlled,
		mapEditInternal,
		setMapEditInternal,
		floorMapLayoutRef,
		reservationFloorMapViewportOverlay,
		setRemoteFloorPlanView,
		floorMapItemClickBefore,
		engineLocale,
		floorMapHudTableDrawer
	});
	const data = isInternalListData ? gridBookingData.data : dataProp !== null && dataProp !== void 0 ? dataProp : [];
	const loadingShown = require_useReservationLoadingShownDebounced.useReservationLoadingShownDebounced(isInternalListData ? gridBookingData.loading : loadingProp !== null && loadingProp !== void 0 ? loadingProp : false);
	const total = isInternalListData ? gridBookingData.total : totalProp !== null && totalProp !== void 0 ? totalProp : 0;
	const pagination = isInternalListData ? gridBookingData.pagination : paginationProp !== null && paginationProp !== void 0 ? paginationProp : {
		pageNumber: 1,
		pageSize: 50
	};
	const onPageChange = isInternalListData ? gridBookingData.onPageChange : onPageChangeProp;
	const searchParams = isInternalListData ? gridBookingData.searchParams : searchParamsProp !== null && searchParamsProp !== void 0 ? searchParamsProp : {};
	const onGridBookingSearch = (0, react.useCallback)((params) => {
		gridBookingData.onSearch(require_reservationDataUtils.mergeGridBookingSearchParams(params));
	}, [gridBookingData.onSearch]);
	const onSearch = isInternalListData ? onGridBookingSearch : onSearchProp;
	const onReset = isInternalListData ? gridBookingData.onReset : onResetProp;
	const handleRouteJump = (0, ahooks.useMemoizedFn)((routePath) => {
		var _app$history, _app$history$push;
		if (!routePath) return;
		setIsNewReservationModalOpen(false);
		app === null || app === void 0 || (_app$history = app.history) === null || _app$history === void 0 || (_app$history$push = _app$history.push) === null || _app$history$push === void 0 || _app$history$push.call(_app$history, routePath);
	});
	const handleOpenNewReservationModal = (0, ahooks.useMemoizedFn)(() => {
		if (newReservationRoutes.length === 1) {
			handleRouteJump(newReservationRoutes[0].router);
			return;
		}
		setIsNewReservationModalOpen(true);
	});
	const handleCloseNewReservationModal = (0, ahooks.useMemoizedFn)(() => {
		setIsNewReservationModalOpen(false);
	});
	(0, react.useEffect)(() => {
		if (!followWallClock) return;
		const tick = () => {
			var _onScheduleChangeRef$;
			const now = (0, dayjs.default)();
			const next = {
				date: now.startOf("day"),
				at: now
			};
			if (scheduleValueProp === void 0) setInternalSchedule(next);
			(_onScheduleChangeRef$ = onScheduleChangeRef.current) === null || _onScheduleChangeRef$ === void 0 || _onScheduleChangeRef$.call(onScheduleChangeRef, next);
			/** 跟随当前：立即提交日程，patch / 外部 onSearch 由 debouncedSchedule effect 统一处理 */
			flushCommittedSchedule(next);
		};
		tick();
		const id = window.setInterval(tick, 3e4);
		return () => window.clearInterval(id);
	}, [
		followWallClock,
		scheduleValueProp,
		flushCommittedSchedule
	]);
	const defaultScheduleEnd = (0, react.useMemo)(() => /* @__PURE__ */ react.default.createElement(require_PisellReservationSubcomponents.PisellReservationScheduleEndActions, { onNewReservation: handleOpenNewReservationModal }), [handleOpenNewReservationModal]);
	const effectiveScheduleEndSlot = (0, react.useMemo)(() => {
		const slotNode = scheduleEndSlotProp !== null && scheduleEndSlotProp !== void 0 ? scheduleEndSlotProp : defaultScheduleEnd;
		return /* @__PURE__ */ react.default.createElement("div", { onClickCapture: (event) => {
			const target = event.target;
			if (!(target === null || target === void 0 ? void 0 : target.closest(".pisell-reservation-new-btn"))) return;
			/** 日程带子组件内点击「新建」时，阻止事件冒泡到 ScheduleBand，避免误触日期导航 */
			event.preventDefault();
			event.stopPropagation();
			handleOpenNewReservationModal();
		} }, slotNode);
	}, [
		scheduleEndSlotProp,
		defaultScheduleEnd,
		handleOpenNewReservationModal
	]);
	const bookingToolBar = bookingChildProps.toolBar;
	/** 时间轴密度：优先用宿主 getTimelineHighlights；否则用本地按预约行计算 */
	const loadReservationDensity = (0, react.useCallback)(function() {
		var _ref2 = require_asyncToGenerator._asyncToGenerator(function* ({ referenceDate, stepMinutes }) {
			var _timeNavigatorPropsPr;
			const slotCount = require_reservationDensity.reservationTimelineAxisSlotCount(referenceDate, stepMinutes, (_timeNavigatorPropsPr = timeNavigatorPropsProp === null || timeNavigatorPropsProp === void 0 ? void 0 : timeNavigatorPropsProp.range) !== null && _timeNavigatorPropsPr !== void 0 ? _timeNavigatorPropsPr : require_reservationConstants.RESERVATION_TIMELINE_BUSINESS_RANGE);
			if (salesTimelineHighlights != null && salesTimelineHighlights.length > 0) return require_reservationDensity.fitTimelineHighlightsToSlotCount(salesTimelineHighlights, slotCount);
			return require_reservationDensity.computeReservationDensityBuckets(isInternalListData ? floorDayBookingData.data : data, referenceDate, stepMinutes);
		});
		return function(_x) {
			return _ref2.apply(this, arguments);
		};
	}(), [
		isInternalListData,
		floorDayBookingData.data,
		data,
		salesTimelineHighlights,
		timeNavigatorPropsProp === null || timeNavigatorPropsProp === void 0 || (_timeNavigatorPropsPr2 = timeNavigatorPropsProp.range) === null || _timeNavigatorPropsPr2 === void 0 ? void 0 : _timeNavigatorPropsPr2.start,
		timeNavigatorPropsProp === null || timeNavigatorPropsProp === void 0 || (_timeNavigatorPropsPr3 = timeNavigatorPropsProp.range) === null || _timeNavigatorPropsPr3 === void 0 ? void 0 : _timeNavigatorPropsPr3.end
	]);
	const toolBarMerged = (0, react.useMemo)(() => {
		const _ref3 = toolBarProp !== null && toolBarProp !== void 0 ? toolBarProp : {}, { tabs: extraTabs, topRight: topRightProp, bottomLeft: bottomLeftProp } = _ref3, restToolbar = require_objectWithoutProperties._objectWithoutProperties(_ref3, _excluded2);
		return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, bookingToolBar !== null && bookingToolBar !== void 0 ? bookingToolBar : {}), restToolbar), {}, {
			tabs: /* @__PURE__ */ react.default.createElement(require_PisellReservationSubcomponents.PisellReservationToolbarTabs, {
				extraTabs,
				schedule,
				onScheduleChange: handleScheduleChange,
				scheduleProps: schedulePropsProp,
				timeNavigatorProps: timeNavigatorPropsProp,
				scheduleStartSlot: scheduleStartSlotProp !== null && scheduleStartSlotProp !== void 0 ? scheduleStartSlotProp : /* @__PURE__ */ react.default.createElement(require_PisellReservationSubcomponents.ReservationDefaultScheduleStart, null),
				scheduleEndSlot: effectiveScheduleEndSlot,
				followWallClock,
				onFollowWallClockToggle: () => setFollowWallClock((v) => !v),
				onTimeNavigatorUserInteraction: () => setFollowWallClock(false),
				loadDensity: loadReservationDensity
			}),
			topRight: /* @__PURE__ */ react.default.createElement(require_PisellReservationSubcomponents.ReservationGridTopRight, { extra: topRightProp }),
			bottomLeft: bottomLeftProp !== null && bottomLeftProp !== void 0 ? bottomLeftProp : null
		});
	}, [
		bookingToolBar,
		toolBarProp,
		schedule,
		handleScheduleChange,
		scheduleStartSlotProp,
		effectiveScheduleEndSlot,
		followWallClock,
		timeNavigatorPropsProp,
		schedulePropsProp,
		loadReservationDensity
	]);
	const recordBoardGrid = (0, react.useMemo)(() => {
		return bookingChildProps.grid;
	}, [bookingChildProps.grid]);
	/** HUD 内嵌表单独小号，不修改主 RecordBoard 共用的 grid 引用 */
	const hudDrawerGrid = (0, react.useMemo)(() => {
		const g = recordBoardGrid;
		if (g == null || typeof g !== "object") return { size: "small" };
		return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, g), {}, { size: "small" });
	}, [recordBoardGrid]);
	const fillHeight = (_scroll$autoCalc = recordBoardGrid === null || recordBoardGrid === void 0 || (_scroll = recordBoardGrid.scroll) === null || _scroll === void 0 ? void 0 : _scroll.autoCalc) !== null && _scroll$autoCalc !== void 0 ? _scroll$autoCalc : true;
	return /* @__PURE__ */ react.default.createElement(_pisell_date_picker.LocalizationProvider, {
		dateAdapter: _pisell_date_picker_es_AdapterDayjs.AdapterDayjs,
		adapterLocale: muiDatePickerAdapterLocale
	}, /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("pisell-reservation-page", className),
		style
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellRecordBoard, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, rest), {}, {
		fillHeight,
		rowKey,
		data,
		dataSources,
		loading: loadingShown,
		total,
		pagination,
		onPageChange,
		searchParams,
		onSearch,
		onReset,
		grid: recordBoardGrid,
		toolBar: toolBarMerged,
		search: bookingChildProps.search,
		batchActionBar: bookingChildProps.batchActionBar,
		floorMap: floorMapMerged,
		defaultBodyView: "floorMap",
		bodyViewStorageKey,
		bodyViewSwitchable,
		lockedBodyView,
		floorMapLayoutRef
	}), /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellRecordBoard.ShellFrame, null, /* @__PURE__ */ react.default.createElement(require_PisellReservationSubcomponents.RecordBoardBodyViewCapture, { bodyViewRef }), /* @__PURE__ */ react.default.createElement(require_PisellReservationSubcomponents.ScheduleSyncOnFloorEnter, {
		schedule,
		isInternalListData,
		patchSearchParams: floorDayBookingData.patchSearchParams
	}), /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellRecordBoard.GridLayout, null), /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellRecordBoard.FloorMap, null))), /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellModal, {
		platform: "pc",
		open: isNewReservationModalOpen,
		title: _pisell_utils.locales.getText(require_reservationConstants.I18N_NEW_MODAL_TITLE),
		onCancel: handleCloseNewReservationModal,
		maskClosable: true,
		footer: null,
		width: 520,
		wrapClassName: "pisell-reservation-new-modal-wrap",
		destroyOnClose: true
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-new-modal-placeholder" }, newReservationRoutes.length > 0 ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-new-modal-route-list" }, newReservationRoutes.map((routeItem) => /* @__PURE__ */ react.default.createElement("button", {
		key: `${routeItem.router}-${routeItem.pageName}`,
		type: "button",
		className: "pisell-reservation-new-modal-route-item",
		onClick: () => handleRouteJump(routeItem.router)
	}, /* @__PURE__ */ react.default.createElement("span", { className: "pisell-reservation-new-modal-route-name" }, routeItem.pageName), /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, {
		type: "icon-right-arrow",
		className: "pisell-reservation-new-modal-route-arrow"
	})))) : /* @__PURE__ */ react.default.createElement("p", { className: "pisell-reservation-new-modal-empty" }, _pisell_utils.locales.getText(require_reservationConstants.I18N_NEW_MODAL_PLACEHOLDER)))), /* @__PURE__ */ react.default.createElement(require_ReservationBookingDetailModal.ReservationBookingDetailModal, {
		open: bookingDetailOpen,
		onClose: closeBookingDetailModal,
		raw: bookingDetailRaw,
		tableRow: bookingDetailRow,
		sceneElementName: bookingDetailSceneName
	}), fab ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-fab" }, fab) : null, showVenueHudDock ? /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("pisell-reservation-hud-dock", hudDrawerOpen && "pisell-reservation-hud-dock--expanded"),
		role: "dialog",
		"aria-modal": "false",
		"aria-expanded": hudDrawerOpen,
		"aria-label": _pisell_utils.locales.getText(require_reservationConstants.I18N_HUD_TABLE_DRAWER_TITLE)
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-hud-dock-header" }, /* @__PURE__ */ react.default.createElement(require_ReservationFloorMapHud.ReservationFloorMapHudTitleBar, {
		items: hudMapItems,
		dataSources,
		actionMode: hudDrawerOpen ? "collapse" : "expand",
		onAction: hudDrawerOpen ? closeHudTableDrawer : handleOpenHudTableDrawer,
		embedded: true,
		className: "pisell-reservation-hud-dock-title-inner"
	})), hudDrawerOpen ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-hud-dock-body" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-hud-dock-record-board" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellRecordBoard, {
		columnVisibilityStorageKey: require_reservationConstants.PISELL_RESERVATION_HUD_DRAWER_COLUMN_STORAGE_KEY,
		rowKey,
		data: hudDrawerPagedRows,
		loading: hudDrawerLoading,
		total: hudDrawerFilteredTotal,
		pagination: hudDrawerBookingPagination,
		onPageChange: hudDrawerOnPageChange,
		paginationConfig: hudRecordBoardPaginationConfig,
		searchParams: hudDrawerLocalSearchParams,
		onSearch: hudDrawerOnSearch,
		onReset: hudDrawerOnReset,
		grid: hudDrawerGrid,
		toolBar: hudDrawerToolBar,
		batchActionBar: bookingChildProps.batchActionBar,
		defaultBodyView: "grid",
		bodyViewSwitchable: false,
		lockedBodyView: "grid"
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellRecordBoard.ShellFrame, null, /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellRecordBoard.GridLayout, null))))) : null) : null));
};
//#endregion
exports.PisellReservationCore = PisellReservationCore;
