require("../../../_virtual/_rolldown/runtime.js");
const require_reservationCards = require("../floorMap/reservationCards.js");
const require_floorMapHostCheckout = require("../floorMap/floorMapHostCheckout.js");
let react = require("react");
//#region src/plus/pisellReservation/hooks/useFloorMapBookingInteraction.ts
/**
* 只读平面图点击 → 宿主结账抽屉或内置预约详情弹窗的状态与 `floorMapItemClickBefore`。
*/
function useFloorMapBookingInteraction(options) {
	const { engineCtx, onFloorMapBookingClick } = options;
	const [bookingDetailOpen, setBookingDetailOpen] = (0, react.useState)(false);
	const [bookingDetailRaw, setBookingDetailRaw] = (0, react.useState)(null);
	const [bookingDetailRow, setBookingDetailRow] = (0, react.useState)(null);
	const [bookingDetailSceneName, setBookingDetailSceneName] = (0, react.useState)(void 0);
	return {
		bookingDetailOpen,
		bookingDetailRaw,
		bookingDetailRow,
		bookingDetailSceneName,
		closeBookingDetailModal: (0, react.useCallback)((e) => {
			var _e$nativeEvent, _e$nativeEvent$stopIm;
			e === null || e === void 0 || e.stopPropagation();
			e === null || e === void 0 || (_e$nativeEvent = e.nativeEvent) === null || _e$nativeEvent === void 0 || (_e$nativeEvent$stopIm = _e$nativeEvent.stopImmediatePropagation) === null || _e$nativeEvent$stopIm === void 0 || _e$nativeEvent$stopIm.call(_e$nativeEvent);
			window.setTimeout(() => {
				setBookingDetailOpen(false);
				setBookingDetailRaw(null);
				setBookingDetailRow(null);
				setBookingDetailSceneName(void 0);
			}, 50);
		}, []),
		floorMapItemClickBefore: (0, react.useCallback)((args) => {
			var _args$item$_sceneElem, _args$item$_sceneElem2, _args$item$_sceneElem3, _engineCtx$appHelper, _utils$getData, _utils$getData2, _utils$store, _utils$store$getState, _args$item$_sceneElem4;
			if (args.mode === "edit") return;
			const rowHit = require_reservationCards.findReservationRow(args.item, args.dataSources);
			const list = rowHit === null || rowHit === void 0 ? void 0 : rowHit.floorMapSourceBookings;
			const rec = require_floorMapHostCheckout.resolveFloorMapHostCheckoutRecord(args.event, list);
			if (!rec || typeof rec !== "object") return;
			const rid = rec.id;
			const bid = rec.booking_id;
			if (!(rid != null && String(rid).trim() !== "" || bid != null && String(bid).trim() !== "")) return;
			const rowResolved = rowHit !== null && rowHit !== void 0 ? rowHit : {
				id: String((_args$item$_sceneElem = (_args$item$_sceneElem2 = args.item._sceneElement) === null || _args$item$_sceneElem2 === void 0 || (_args$item$_sceneElem2 = _args$item$_sceneElem2.dataBinding) === null || _args$item$_sceneElem2 === void 0 ? void 0 : _args$item$_sceneElem2.recordId) !== null && _args$item$_sceneElem !== void 0 ? _args$item$_sceneElem : "unknown"),
				code: ((_args$item$_sceneElem3 = args.item._sceneElement) === null || _args$item$_sceneElem3 === void 0 ? void 0 : _args$item$_sceneElem3.name) != null ? String(args.item._sceneElement.name) : "—",
				cardStatus: "available"
			};
			if ((onFloorMapBookingClick === null || onFloorMapBookingClick === void 0 ? void 0 : onFloorMapBookingClick({
				event: args.event,
				raw: rec,
				row: rowResolved,
				dataSources: args.dataSources,
				mode: args.mode
			})) === true) return;
			const utils = engineCtx === null || engineCtx === void 0 || (_engineCtx$appHelper = engineCtx.appHelper) === null || _engineCtx$appHelper === void 0 ? void 0 : _engineCtx$appHelper.utils;
			const shopId = (_utils$getData = utils === null || utils === void 0 || (_utils$getData2 = utils.getData) === null || _utils$getData2 === void 0 ? void 0 : _utils$getData2.call(utils, "shop_id")) !== null && _utils$getData !== void 0 ? _utils$getData : utils === null || utils === void 0 || (_utils$store = utils.store) === null || _utils$store === void 0 || (_utils$store$getState = _utils$store.getState) === null || _utils$store$getState === void 0 || (_utils$store$getState = _utils$store$getState.call(_utils$store)) === null || _utils$store$getState === void 0 || (_utils$store$getState = _utils$store$getState.global) === null || _utils$store$getState === void 0 || (_utils$store$getState = _utils$store$getState.globalConfig) === null || _utils$store$getState === void 0 ? void 0 : _utils$store$getState.id;
			const n = Number(shopId);
			if (Number.isFinite(n) && n === 2155) {
				var _utils$action;
				utils === null || utils === void 0 || (_utils$action = utils.action) === null || _utils$action === void 0 || _utils$action.call(utils, {
					type: "pisell1.handleOpenHostCheckoutDrawer",
					data: { item: rec }
				});
				return;
			}
			const sceneName = ((_args$item$_sceneElem4 = args.item._sceneElement) === null || _args$item$_sceneElem4 === void 0 ? void 0 : _args$item$_sceneElem4.name) != null ? String(args.item._sceneElement.name).trim() : void 0;
			setBookingDetailSceneName(sceneName && sceneName !== "" ? sceneName : void 0);
			setBookingDetailRaw(rec);
			setBookingDetailRow(rowResolved);
			setBookingDetailOpen(true);
		}, [engineCtx, onFloorMapBookingClick])
	};
}
//#endregion
exports.useFloorMapBookingInteraction = useFloorMapBookingInteraction;
