var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/pisellReservation/hooks/useFloorMapBookingInteraction.ts
var useFloorMapBookingInteraction_exports = {};
__export(useFloorMapBookingInteraction_exports, {
  useFloorMapBookingInteraction: () => useFloorMapBookingInteraction
});
module.exports = __toCommonJS(useFloorMapBookingInteraction_exports);
var import_react = require("react");
var import_reservationCards = require("../floorMap/reservationCards");
var import_floorMapHostCheckout = require("../floorMap/floorMapHostCheckout");
function useFloorMapBookingInteraction(options) {
  const { engineCtx, onFloorMapBookingClick } = options;
  const [bookingDetailOpen, setBookingDetailOpen] = (0, import_react.useState)(false);
  const [bookingDetailRaw, setBookingDetailRaw] = (0, import_react.useState)(null);
  const [bookingDetailRow, setBookingDetailRow] = (0, import_react.useState)(null);
  const [bookingDetailSceneName, setBookingDetailSceneName] = (0, import_react.useState)(void 0);
  const closeBookingDetailModal = (0, import_react.useCallback)(
    (e) => {
      var _a, _b;
      e == null ? void 0 : e.stopPropagation();
      (_b = (_a = e == null ? void 0 : e.nativeEvent) == null ? void 0 : _a.stopImmediatePropagation) == null ? void 0 : _b.call(_a);
      window.setTimeout(() => {
        setBookingDetailOpen(false);
        setBookingDetailRaw(null);
        setBookingDetailRow(null);
        setBookingDetailSceneName(void 0);
      }, 50);
    },
    []
  );
  const floorMapItemClickBefore = (0, import_react.useCallback)(
    (args) => {
      var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
      if (args.mode === "edit") return;
      const rowHit = (0, import_reservationCards.findReservationRow)(args.item, args.dataSources);
      const list = rowHit == null ? void 0 : rowHit.floorMapSourceBookings;
      const rec = (0, import_floorMapHostCheckout.resolveFloorMapHostCheckoutRecord)(args.event, list);
      if (!rec || typeof rec !== "object") return;
      const rid = rec.id;
      const bid = rec.booking_id;
      const hasId = rid != null && String(rid).trim() !== "" || bid != null && String(bid).trim() !== "";
      if (!hasId) return;
      const rowResolved = rowHit ?? {
        id: String(
          ((_b = (_a = args.item._sceneElement) == null ? void 0 : _a.dataBinding) == null ? void 0 : _b.recordId) ?? "unknown"
        ),
        code: ((_c = args.item._sceneElement) == null ? void 0 : _c.name) != null ? String(args.item._sceneElement.name) : "—",
        cardStatus: "available"
      };
      const consumed = onFloorMapBookingClick == null ? void 0 : onFloorMapBookingClick({
        event: args.event,
        raw: rec,
        row: rowResolved,
        dataSources: args.dataSources,
        mode: args.mode
      });
      if (consumed === true) return;
      const utils = (_d = engineCtx == null ? void 0 : engineCtx.appHelper) == null ? void 0 : _d.utils;
      const shopId = ((_e = utils == null ? void 0 : utils.getData) == null ? void 0 : _e.call(utils, "shop_id")) ?? ((_j = (_i = (_h = (_g = (_f = utils == null ? void 0 : utils.store) == null ? void 0 : _f.getState) == null ? void 0 : _g.call(_f)) == null ? void 0 : _h.global) == null ? void 0 : _i.globalConfig) == null ? void 0 : _j.id);
      const n = Number(shopId);
      const isLegacyCheckoutShop = Number.isFinite(n) && n === 2155;
      if (isLegacyCheckoutShop) {
        (_k = utils == null ? void 0 : utils.action) == null ? void 0 : _k.call(utils, {
          type: "pisell1.handleOpenHostCheckoutDrawer",
          data: { item: rec }
        });
        return;
      }
      const sceneName = ((_l = args.item._sceneElement) == null ? void 0 : _l.name) != null ? String(args.item._sceneElement.name).trim() : void 0;
      setBookingDetailSceneName(
        sceneName && sceneName !== "" ? sceneName : void 0
      );
      setBookingDetailRaw(rec);
      setBookingDetailRow(rowResolved);
      setBookingDetailOpen(true);
    },
    [engineCtx, onFloorMapBookingClick]
  );
  return {
    bookingDetailOpen,
    bookingDetailRaw,
    bookingDetailRow,
    bookingDetailSceneName,
    closeBookingDetailModal,
    floorMapItemClickBefore
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useFloorMapBookingInteraction
});
