function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
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); }
import { useCallback, useEffect, useRef, useState } from 'react';
import { FLOOR_MAP_BUILTIN_SHAPE_ELEMENT_KIND, FLOOR_MAP_IMAGE_ELEMENT_KIND, FLOOR_MAP_STAGE_ELEMENT_KIND } from '@pisell/materials';
import { findReservationRow } from "../floorMap/reservationCards";
import { resolveFloorMapHostCheckoutRecord } from "../floorMap/floorMapHostCheckout";
import { extractFloorMapSourceBookingForRow, findMergedTableRowForBookingRaw } from "../data/calendarAdapter";
import { extractResourceRecordIds } from "../data/bookingToReservationTables";
import { resolveFloorRoomCardContactTiers } from "../floorRoomCard/mapRowToFloorRoomCardData";
import { openNewReservationBookingFromHost } from "../utils/reservationTicketBookingHostParams";
/**
 * 与详情弹窗 {@link bookingDetailOrderStripFromRaw} 同源：`order.summary` 总价/应付、商品件数与顶层
 * `products` 行数。仅改时间时不一定会触达 summary；加商品/改价会变更 summary 或 product 行。
 */
function bookingOrderFinancialSig(raw) {
  var _sum$total_amount, _sum$expect_amount, _sum$product_quantity;
  var order = raw.order;
  var sum = order === null || order === void 0 ? void 0 : order.summary;
  var products = raw.products;
  var productLineCount = Array.isArray(products) ? products.filter(function (x) {
    return x && _typeof(x) === 'object';
  }).length : -1;
  return [String((_sum$total_amount = sum === null || sum === void 0 ? void 0 : sum.total_amount) !== null && _sum$total_amount !== void 0 ? _sum$total_amount : ''), String((_sum$expect_amount = sum === null || sum === void 0 ? void 0 : sum.expect_amount) !== null && _sum$expect_amount !== void 0 ? _sum$expect_amount : ''), String((_sum$product_quantity = sum === null || sum === void 0 ? void 0 : sum.product_quantity) !== null && _sum$product_quantity !== void 0 ? _sum$product_quantity : ''), String(productLineCount)].join(':');
}

/** 与详情条带一致：展示用支付态读 `order.payment_status ?? raw.payment_status`（与 order_payment_status 可能不同源） */
function bookingPaymentStatusDisplaySig(raw) {
  var _ref, _ref2, _order$payment_status;
  var order = raw.order;
  var pay = (_ref = (_ref2 = (_order$payment_status = order === null || order === void 0 ? void 0 : order.payment_status) !== null && _order$payment_status !== void 0 ? _order$payment_status : order === null || order === void 0 ? void 0 : order.order_payment_status) !== null && _ref2 !== void 0 ? _ref2 : raw.payment_status) !== null && _ref !== void 0 ? _ref : raw.order_payment_status;
  return String(pay !== null && pay !== void 0 ? pay : '');
}

/**
 * 与 {@link resolveFloorRoomCardContactTiers} 一致：holder → contacts_info → customer 各层姓名/电话，
 * 推送只改联系人时使用。
 */
function bookingContactTiersSig(raw) {
  var tiers = resolveFloorRoomCardContactTiers(raw);
  if (!(tiers !== null && tiers !== void 0 && tiers.length)) return '';
  return tiers.map(function (t) {
    var _t$name;
    var phone = t.phone != null && String(t.phone).trim() !== '' ? String(t.phone).trim() : '';
    return "".concat(t.source, ":").concat(String((_t$name = t.name) !== null && _t$name !== void 0 ? _t$name : '').trim(), ":").concat(phone);
  }).join('>');
}

/** 与 {@link rawToBooking} 中 `parseBookingOrderCustomerId` 同源：order.customer_id → order.customer.id */
function bookingOrderCustomerIdSig(raw) {
  var order = raw.order;
  if (!order) return '';
  var top = order.customer_id;
  if (top != null && String(top).trim() !== '') return String(top);
  var c = order.customer;
  var id = c === null || c === void 0 ? void 0 : c.id;
  return id != null && String(id).trim() !== '' ? String(id) : '';
}

/**
 * 弱字段：推送常改但旧签名未覆盖 —— 人数、备注、ISO 起止、订单日程、duration、资源桌位 relation_id、is_next 等。
 * relation_id 与 {@link extractResourceRecordIds} / 换桌一致。
 */
function bookingAuxRealtimeSig(raw) {
  var _raw$number, _raw$notes, _raw$start_at, _raw$end_at, _order$schedule_date, _raw$duration, _raw$sub_type, _ref3, _raw$is_next, _raw$lateTime, _raw$timeoutTime, _raw$remainingReserve, _raw$progressPercent;
  var order = raw.order;
  var resourceIds = extractResourceRecordIds(raw).sort().join(',');
  return [bookingContactTiersSig(raw), String((_raw$number = raw.number) !== null && _raw$number !== void 0 ? _raw$number : ''), String((_raw$notes = raw.notes) !== null && _raw$notes !== void 0 ? _raw$notes : ''), String((_raw$start_at = raw.start_at) !== null && _raw$start_at !== void 0 ? _raw$start_at : ''), String((_raw$end_at = raw.end_at) !== null && _raw$end_at !== void 0 ? _raw$end_at : ''), String((_order$schedule_date = order === null || order === void 0 ? void 0 : order.schedule_date) !== null && _order$schedule_date !== void 0 ? _order$schedule_date : ''), bookingOrderCustomerIdSig(raw), String((_raw$duration = raw.duration) !== null && _raw$duration !== void 0 ? _raw$duration : ''), String((_raw$sub_type = raw.sub_type) !== null && _raw$sub_type !== void 0 ? _raw$sub_type : ''), resourceIds, String((_ref3 = (_raw$is_next = raw.is_next) !== null && _raw$is_next !== void 0 ? _raw$is_next : raw.isNext) !== null && _ref3 !== void 0 ? _ref3 : ''), String((_raw$lateTime = raw.lateTime) !== null && _raw$lateTime !== void 0 ? _raw$lateTime : ''), String((_raw$timeoutTime = raw.timeoutTime) !== null && _raw$timeoutTime !== void 0 ? _raw$timeoutTime : ''), String((_raw$remainingReserve = raw.remainingReserveTime) !== null && _raw$remainingReserve !== void 0 ? _raw$remainingReserve : ''), String((_raw$progressPercent = raw.progressPercent) !== null && _raw$progressPercent !== void 0 ? _raw$progressPercent : '')].join('|');
}

/**
 * 判断预约 raw 是否相对上次有展示相关变化；用于详情 Modal 与画布实时对齐。
 * 含：身份与时间、状态与支付、财务 summary、联系人三层、人数/备注/资源桌位、起止 at、宿主进度字段等。
 */
function bookingRawRealtimeSig(raw) {
  var _raw$id, _ref4, _raw$booking_id, _raw$start_time, _raw$end_time, _raw$appointment_stat, _raw$order_payment_st, _raw$status, _order_payment_status, _raw$order;
  return [String((_raw$id = raw.id) !== null && _raw$id !== void 0 ? _raw$id : ''), String((_ref4 = (_raw$booking_id = raw.booking_id) !== null && _raw$booking_id !== void 0 ? _raw$booking_id : raw.booking_uid) !== null && _ref4 !== void 0 ? _ref4 : ''), String((_raw$start_time = raw.start_time) !== null && _raw$start_time !== void 0 ? _raw$start_time : ''), String((_raw$end_time = raw.end_time) !== null && _raw$end_time !== void 0 ? _raw$end_time : ''), String((_raw$appointment_stat = raw.appointment_status) !== null && _raw$appointment_stat !== void 0 ? _raw$appointment_stat : ''), String((_raw$order_payment_st = raw.order_payment_status) !== null && _raw$order_payment_st !== void 0 ? _raw$order_payment_st : ''), String((_raw$status = raw.status) !== null && _raw$status !== void 0 ? _raw$status : ''), String((_order_payment_status = (_raw$order = raw.order) === null || _raw$order === void 0 ? void 0 : _raw$order.order_payment_status) !== null && _order_payment_status !== void 0 ? _order_payment_status : ''), bookingPaymentStatusDisplaySig(raw), bookingOrderFinancialSig(raw), bookingAuxRealtimeSig(raw)].join('|');
}

/** 与 useEngineContext 返回值形状一致（不直接 import hook），避免类型循环 */

var SYNTHETIC_MOUSE_EVENT = {
  stopPropagation: function stopPropagation() {},
  preventDefault: function preventDefault() {},
  nativeEvent: {
    stopImmediatePropagation: function stopImmediatePropagation() {}
  }
};

/**
 * 只读平面图点击 → 宿主结账抽屉或内置预约详情弹窗的状态与 `floorMapItemClickBefore`；
 * 日历受控 raw 通过 `openBookingDetailFromRaw` 走同一套详情。
 */
export function useFloorMapBookingInteraction(options) {
  var engineCtx = options.engineCtx,
    onFloorMapBookingClick = options.onFloorMapBookingClick,
    dataSources = options.dataSources,
    mergedTableRows = options.mergedTableRows,
    reservationBiz = options.reservationBiz,
    resourceSelectMode = options.resourceSelectMode,
    associatedMenuListIds = options.associatedMenuListIds,
    reservationRuleProduct = options.reservationRuleProduct;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    bookingDetailOpen = _useState2[0],
    setBookingDetailOpen = _useState2[1];
  /** 内置预约详情 Modal 打开时，阅读态平面图对应图元 id（与 `FloorMapMergedItem.id` / ItemLayer rowKey 一致） */
  var _useState3 = useState(null),
    _useState4 = _slicedToArray(_useState3, 2),
    readModeSelectedFloorItemId = _useState4[0],
    setReadModeSelectedFloorItemId = _useState4[1];
  var _useState5 = useState(null),
    _useState6 = _slicedToArray(_useState5, 2),
    bookingDetailRaw = _useState6[0],
    setBookingDetailRaw = _useState6[1];
  var _useState7 = useState(null),
    _useState8 = _slicedToArray(_useState7, 2),
    bookingDetailRow = _useState8[0],
    setBookingDetailRow = _useState8[1];
  var _useState9 = useState(undefined),
    _useState10 = _slicedToArray(_useState9, 2),
    bookingDetailSceneName = _useState10[0],
    setBookingDetailSceneName = _useState10[1];
  var bookingDetailRawRef = useRef(bookingDetailRaw);
  bookingDetailRawRef.current = bookingDetailRaw;
  var lastDetailSyncSigRef = useRef('');

  /**
   * 画布外 `tables` 随推送更新时，若内置预约详情 Modal 仍打开，则用最新 `floorMapSourceBookings`
   * 条目刷新 `raw` / `tableRow`，使时间、支付态、订单 summary / 商品与画布一致（签名含 {@link bookingOrderFinancialSig}）。
   */
  useEffect(function () {
    if (!bookingDetailOpen) {
      lastDetailSyncSigRef.current = '';
      setReadModeSelectedFloorItemId(null);
      return;
    }
    var cur = bookingDetailRawRef.current;
    if (!cur) return;
    var row = findMergedTableRowForBookingRaw(cur, mergedTableRows);
    if (!row) return;
    var fresh = extractFloorMapSourceBookingForRow(cur, row);
    if (!fresh) return;
    var sig = bookingRawRealtimeSig(fresh);
    if (sig === lastDetailSyncSigRef.current) return;
    lastDetailSyncSigRef.current = sig;
    setBookingDetailRaw(fresh);
    setBookingDetailRow(row);
  }, [bookingDetailOpen, mergedTableRows]);

  /**
   * 同步关闭：直接清空 open / raw / row / sceneName，给「程序化关闭」用
   * （如 action success 后由父级链路触发 close）。
   *
   * 这一路径不存在「click 事件冒泡到下层画布、误触图元再次开 Modal」的问题，
   * 必须立即关，避免 `await refreshAsync()` 期间 `useEffect[bookingDetailOpen,
   * mergedTableRows]` 又用 `extractFloorMapSourceBookingForRow` 把
   * `bookingDetailRaw` 回灌成「completed 状态的新 raw」，导致弹窗内容
   * 在 fade out 前再亮一帧、视觉上像 Modal 闪了一下。
   */
  var closeBookingDetailNow = useCallback(function () {
    setBookingDetailOpen(false);
    setBookingDetailRaw(null);
    setBookingDetailRow(null);
    setBookingDetailSceneName(undefined);
  }, []);

  /**
   * 事件路径关闭：保留 50ms `setTimeout`，避免 mask / 关闭按钮 click 冒泡
   * 立即穿透到下层平面图图元，再触发 `floorMapItemClickBefore` 把同一个
   * Modal 又开起来。仅给 Modal `onCancel` / 头部关闭按钮等真正来自鼠标事件
   * 的入口使用；其它「确认操作完成后程序化关闭」一律走 {@link closeBookingDetailNow}。
   */
  var closeBookingDetailModal = useCallback(function (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(function () {
      closeBookingDetailNow();
    }, 50);
  }, [closeBookingDetailNow]);
  var showBookingDetail = useCallback(function (opts) {
    var _engineCtx$appHelper, _utils$getData, _utils$getData2, _utils$store, _utils$store$getState;
    var rec = opts.rec,
      rowResolved = opts.rowResolved,
      event = opts.event,
      sceneElementName = opts.sceneElementName,
      floorMapItemId = opts.floorMapItemId;
    var ev = event !== null && event !== void 0 ? event : SYNTHETIC_MOUSE_EVENT;
    var consumed = onFloorMapBookingClick === null || onFloorMapBookingClick === void 0 ? void 0 : onFloorMapBookingClick({
      event: ev,
      raw: rec,
      row: rowResolved,
      dataSources: dataSources,
      mode: 'read'
    });
    if (consumed === true) return;
    var utils = engineCtx === null || engineCtx === void 0 || (_engineCtx$appHelper = engineCtx.appHelper) === null || _engineCtx$appHelper === void 0 ? void 0 : _engineCtx$appHelper.utils;
    var 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;
    var n = Number(shopId);
    var isLegacyCheckoutShop = Number.isFinite(n) && n === 2155;

    /**
     * 空桌走详情 Modal 时 rec 是占位空对象，没有 id / booking_id；
     * 旧店铺结账抽屉强依赖具体 booking，故空 rec 时跳过此分支，
     * 直接进内置预约详情 Modal 看历史已完成 / 未付款记录。
     */
    var recHasBooking = function () {
      var rid = rec.id;
      var bid = rec.booking_id;
      return rid != null && String(rid).trim() !== '' || bid != null && String(bid).trim() !== '';
    }();
    if (isLegacyCheckoutShop && reservationBiz !== 'dine_in' && recHasBooking) {
      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;
    }
    var sn = sceneElementName === null || sceneElementName === void 0 ? void 0 : sceneElementName.trim();
    setBookingDetailSceneName(sn && sn !== '' ? sn : undefined);
    lastDetailSyncSigRef.current = bookingRawRealtimeSig(rec);
    setBookingDetailRaw(rec);
    setBookingDetailRow(rowResolved);
    if (floorMapItemId != null && String(floorMapItemId).trim() !== '') {
      setReadModeSelectedFloorItemId(String(floorMapItemId));
    } else {
      setReadModeSelectedFloorItemId(null);
    }
    setBookingDetailOpen(true);
  }, [dataSources, engineCtx, onFloorMapBookingClick]);
  var floorMapItemClickBefore = useCallback(function (args) {
    var _args$item$elementKin, _args$item$_sceneElem, _args$item$_sceneElem5, _args$item$_sceneElem6, _args$item$_sceneElem7, _args$item$_sceneElem8;
    if (args.mode === 'edit') return;
    /**
     * 「无数据源绑定」的纯视觉图元——图片 / 内置图形 / 舞台装饰——都没有
     * resourceId 也不挂 booking，既不能进资源选择，也无预约详情可看。
     * 直接短路掉，避免阅读态点中后弹出空白 ReservationBookingDetailModal。
     * 三者在 `floorMapElementKindUtils#getSwappableElementKindsInSameCategory`
     * 中也是并列排除的，保持口径一致。
     */
    var elementKind = (_args$item$elementKin = args.item.elementKind) !== null && _args$item$elementKin !== void 0 ? _args$item$elementKin : (_args$item$_sceneElem = args.item._sceneElement) === null || _args$item$_sceneElem === void 0 ? void 0 : _args$item$_sceneElem.elementKind;
    if (elementKind === FLOOR_MAP_IMAGE_ELEMENT_KIND || elementKind === FLOOR_MAP_BUILTIN_SHAPE_ELEMENT_KIND || elementKind === FLOOR_MAP_STAGE_ELEMENT_KIND) {
      return;
    }
    var rowHit = findReservationRow(args.item, args.dataSources);
    if (resourceSelectMode !== null && resourceSelectMode !== void 0 && resourceSelectMode.enabled) {
      var _ref5, _args$item$_sceneElem2, _args$item$_sceneElem3, _args$item$_sceneElem4;
      var _rowResolved = rowHit !== null && rowHit !== void 0 ? rowHit : {
        id: String((_ref5 = (_args$item$_sceneElem2 = (_args$item$_sceneElem3 = args.item._sceneElement) === null || _args$item$_sceneElem3 === void 0 || (_args$item$_sceneElem3 = _args$item$_sceneElem3.dataBinding) === null || _args$item$_sceneElem3 === void 0 ? void 0 : _args$item$_sceneElem3.recordId) !== null && _args$item$_sceneElem2 !== void 0 ? _args$item$_sceneElem2 : args.item.id) !== null && _ref5 !== void 0 ? _ref5 : 'unknown'),
        code: ((_args$item$_sceneElem4 = args.item._sceneElement) === null || _args$item$_sceneElem4 === void 0 ? void 0 : _args$item$_sceneElem4.name) != null ? String(args.item._sceneElement.name) : '—',
        cardStatus: 'available'
      };
      resourceSelectMode.onSelectResource({
        item: args.item,
        row: _rowResolved,
        resource: {
          id: _rowResolved.id,
          relation_id: _rowResolved.id,
          form_id: _rowResolved.form_id,
          code: _rowResolved.code,
          main_field: _rowResolved.main_field,
          raw: _rowResolved
        }
      });
      return;
    }
    var list = rowHit === null || rowHit === void 0 ? void 0 : rowHit.floorMapSourceBookings;
    var rec = resolveFloorMapHostCheckoutRecord(args.event, list);

    /**
     * 「当下点击是否命中某个具体 booking」：rec 存在且带 id / booking_id。
     * 与「该资源是否有任何历史订单」（`row.bookingCount`）分两件事：
     * - 命中具体 booking → 详情 Modal 直接落到该 booking
     * - 未命中但 bookingCount > 0 → 详情 Modal 列出该资源历史/未付款订单
     * - 未命中且 bookingCount === 0 / 缺失 → 走宿主新建
     * 历史已完成 / 未付款记录由 Modal 内 `sales.getResourceBookingItem`
     * 以 `tableRow` 解出的 resourceId 为锚点拉取。
     */
    var recHasValidBooking = function () {
      if (!rec || _typeof(rec) !== 'object') return false;
      var rid = rec.id;
      var bid = rec.booking_id;
      return rid != null && String(rid).trim() !== '' || bid != null && String(bid).trim() !== '';
    }();
    var rowResolved = rowHit !== null && rowHit !== void 0 ? rowHit : {
      id: String((_args$item$_sceneElem5 = (_args$item$_sceneElem6 = args.item._sceneElement) === null || _args$item$_sceneElem6 === void 0 || (_args$item$_sceneElem6 = _args$item$_sceneElem6.dataBinding) === null || _args$item$_sceneElem6 === void 0 ? void 0 : _args$item$_sceneElem6.recordId) !== null && _args$item$_sceneElem5 !== void 0 ? _args$item$_sceneElem5 : 'unknown'),
      code: ((_args$item$_sceneElem7 = args.item._sceneElement) === null || _args$item$_sceneElem7 === void 0 ? void 0 : _args$item$_sceneElem7.name) != null ? String(args.item._sceneElement.name) : '—',
      cardStatus: 'available'
    };
    var sceneName = ((_args$item$_sceneElem8 = args.item._sceneElement) === null || _args$item$_sceneElem8 === void 0 ? void 0 : _args$item$_sceneElem8.name) != null ? String(args.item._sceneElement.name).trim() : undefined;

    /**
     * 资源历史订单总数：来自 `sales.getResourceBookingList` 行顶层 `bookingCount`。
     * `> 0` 表示卡片视觉空白（当下没命中具体 booking）但仍有历史/已完成/未付款，
     * 此时点击应进详情 Modal，不能直接走新建。缺失或不是有限数按 0 处理。
     */
    var rowBookingCount = typeof (rowHit === null || rowHit === void 0 ? void 0 : rowHit.bookingCount) === 'number' && Number.isFinite(rowHit.bookingCount) ? rowHit.bookingCount : 0;
    if (!recHasValidBooking && rowBookingCount === 0) {
      var _engineCtx$appHelper2;
      /**
       * 仍先给宿主 `onFloorMapBookingClick` 一次拦截机会（raw 为占位空对象），
       * 与原 showBookingDetail 路径保持口径一致；返回 true 即视为消费、不再
       * 派发新建。
       */
      var consumed = onFloorMapBookingClick === null || onFloorMapBookingClick === void 0 ? void 0 : onFloorMapBookingClick({
        event: args.event,
        raw: {},
        row: rowResolved,
        dataSources: args.dataSources,
        mode: 'read'
      });
      if (consumed === true) return;

      /**
       * 与详情 Modal 右上角「New」按钮 `handleHeaderNewOrderClick` 完全同源；
       * dine_in 缺 `reservationRuleProduct` 等情况拼不出 createModeConfig 时，
       * 按既定策略 no-op，不再回退打开详情 Modal。
       */
      openNewReservationBookingFromHost({
        appHelperUtils: engineCtx === null || engineCtx === void 0 || (_engineCtx$appHelper2 = engineCtx.appHelper) === null || _engineCtx$appHelper2 === void 0 ? void 0 : _engineCtx$appHelper2.utils,
        reservationBiz: reservationBiz,
        associatedMenuListIds: associatedMenuListIds,
        reservationRuleProduct: reservationRuleProduct,
        row: rowResolved
      });
      return;
    }

    /**
     * 进入详情 Modal：
     * - 命中具体 booking → 透传该 rec
     * - 未命中但 bookingCount > 0 → rec 用占位空对象，Modal 内部按 resourceId 拉历史列表
     */
    var recForDetail = recHasValidBooking ? rec : {};
    showBookingDetail({
      rec: recForDetail,
      rowResolved: rowResolved,
      event: args.event,
      sceneElementName: sceneName,
      floorMapItemId: String(args.item.id)
    });
  }, [showBookingDetail, resourceSelectMode, onFloorMapBookingClick, engineCtx, reservationBiz, associatedMenuListIds, reservationRuleProduct]);
  var openBookingDetailFromRaw = useCallback(function (payload) {
    var _payload$row, _ref6, _ref7, _rec$relation_form_na;
    var rec = payload.raw;
    var rid = rec.id;
    var bid = rec.booking_id;
    var hasId = rid != null && String(rid).trim() !== '' || bid != null && String(bid).trim() !== '';
    if (!hasId) return;
    var rowResolved = (_payload$row = payload.row) !== null && _payload$row !== void 0 ? _payload$row : {
      id: String((_ref6 = rid !== null && rid !== void 0 ? rid : bid) !== null && _ref6 !== void 0 ? _ref6 : 'unknown'),
      code: String((_ref7 = (_rec$relation_form_na = rec.relation_form_name) !== null && _rec$relation_form_na !== void 0 ? _rec$relation_form_na : bid) !== null && _ref7 !== void 0 ? _ref7 : '—'),
      cardStatus: 'booked'
    };
    showBookingDetail({
      rec: rec,
      rowResolved: rowResolved,
      sceneElementName: payload.sceneElementName
    });
  }, [showBookingDetail]);
  return {
    bookingDetailOpen: bookingDetailOpen,
    bookingDetailRaw: bookingDetailRaw,
    bookingDetailRow: bookingDetailRow,
    bookingDetailSceneName: bookingDetailSceneName,
    readModeSelectedFloorItemId: readModeSelectedFloorItemId,
    closeBookingDetailModal: closeBookingDetailModal,
    closeBookingDetailNow: closeBookingDetailNow,
    floorMapItemClickBefore: floorMapItemClickBefore,
    openBookingDetailFromRaw: openBookingDetailFromRaw
  };
}