var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/pisellReservation/PisellReservation.tsx
var PisellReservation_exports = {};
__export(PisellReservation_exports, {
  PisellReservationCore: () => PisellReservationCore
});
module.exports = __toCommonJS(PisellReservation_exports);
var import_react = __toESM(require("react"));
var import_dayjs = __toESM(require("dayjs"));
var import_zh_cn = require("dayjs/locale/zh-cn");
var import_en = require("dayjs/locale/en");
var import_zh_tw = require("dayjs/locale/zh-tw");
var import_classnames = __toESM(require("classnames"));
var import_date_picker = require("@pisell/date-picker");
var import_AdapterDayjs = require("@pisell/date-picker/es/AdapterDayjs");
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_ReservationBookingDetailModal = require("./components/bookingDetailModal/ReservationBookingDetailModal");
var import_floorPlanApi = require("./floorMap/floorPlanApi");
var import_reservationCards = require("./floorMap/reservationCards");
var import_ReservationFloorMapHud = require("./floorMap/ReservationFloorMapHud");
var import_reservationHudTableRows = require("./floorMap/reservationHudTableRows");
var import_useBookingPerspective = require("../pisellSalesManagement/hooks/useBookingPerspective");
var import_usePisellReservationBookingData = require("./hooks/usePisellReservationBookingData");
var import_usePisellReservationResourceTableData = require("./hooks/usePisellReservationResourceTableData");
var import_utils2 = require("../../utils");
var import_PisellReservation = require("./PisellReservation.less");
var import_ahooks = require("ahooks");
var import_serve = require("../pisellSalesManagement/serve");
var import_reservationDensity = require("./data/reservationDensity");
var import_bookingToReservationTables = require("./data/bookingToReservationTables");
var import_hudDrawerLocalListQuery = require("./data/hudDrawerLocalListQuery");
var import_reservationTablesMerge = require("./data/reservationTablesMerge");
var import_reservationDataUtils = require("./data/reservationDataUtils");
var import_floorMapBoundRecordIds = require("./floorMap/floorMapBoundRecordIds");
var import_PisellReservationSubcomponents = require("./components/PisellReservationSubcomponents");
var import_useReservationFloorPlan = require("./floorMap/useReservationFloorPlan");
var import_useReservationFloorMapMerged = require("./floorMap/useReservationFloorMapMerged");
var import_reservationConstants = require("./reservationConstants");
var import_useReservationScheduleDebounced = require("./hooks/useReservationScheduleDebounced");
var import_useReservationSalesHostData = require("./hooks/useReservationSalesHostData");
var import_useNewReservationRoutesFromEngine = require("./hooks/useNewReservationRoutesFromEngine");
var import_useReservationLoadingShownDebounced = require("./hooks/useReservationLoadingShownDebounced");
var import_useFloorMapBookingInteraction = require("./hooks/useFloorMapBookingInteraction");
function ReservationHudMapItemsSync({
  items,
  setItems
}) {
  (0, import_react.useEffect)(() => {
    setItems(items);
  }, [items, setItems]);
  return null;
}
var PisellReservationCore = (props) => {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
  const {
    gridDataSourceKey = import_reservationConstants.GRID_DS_KEY,
    dataSources: dataSourcesProp,
    scheduleValue: scheduleValueProp,
    onScheduleChange,
    toolBar: toolBarProp,
    floorMap: floorMapProp,
    scheduleStartSlot: scheduleStartSlotProp,
    scheduleEndSlot: scheduleEndSlotProp,
    onNewReservation,
    timeNavigatorProps: timeNavigatorPropsProp,
    scheduleProps: schedulePropsProp,
    fab,
    /** 不再作为首屏来源：从 props 剔除以免进入 rest（旧页面 schema 可能仍带此字段） */
    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,
    ...rest
  } = props;
  const hudItemsRef = (0, import_react.useRef)([]);
  const [hudMapItems, setHudMapItems] = (0, import_react.useState)([]);
  const [hudDrawerOpen, setHudDrawerOpen] = (0, import_react.useState)(false);
  const [hudDrawerResourceIds, setHudDrawerResourceIds] = (0, import_react.useState)(null);
  const [hudDrawerLocalSearchParams, setHudDrawerLocalSearchParams] = (0, import_react.useState)({});
  const hudDrawerSearchParamsOpenSnapshotRef = (0, import_react.useRef)(
    {}
  );
  const [hudDrawerListPagination, setHudDrawerListPagination] = (0, import_react.useState)({
    pageNumber: 1,
    pageSize: import_reservationConstants.PISELL_RESERVATION_HUD_LOCAL_PAGE_SIZE
  });
  const isInternalListData = (0, import_reservationDataUtils.shouldUseBuiltinReservationList)(
    dataProp,
    totalProp,
    paginationProp,
    onPageChangeProp
  );
  const resolvedFloorPlanId = floorPlanIdProp === null ? null : floorPlanIdProp === void 0 ? import_floorPlanApi.RESERVATION_DEFAULT_FLOOR_PLAN_ID : floorPlanIdProp;
  const effectiveFloorPlanCode = floorPlanCode ?? import_floorPlanApi.PISELL_RESERVATION_FLOOR_PLAN_CODE;
  const engineCtx = (0, import_useEngineContext.default)();
  const pisellos = (0, import_useEngineContext.usePisellOS)();
  const pisellosRef = (0, import_react.useRef)(pisellos);
  pisellosRef.current = pisellos;
  const hasPisellosGetModule = typeof (pisellos == null ? void 0 : pisellos.getModule) === "function";
  const engineLocale = ((_b = (_a = engineCtx == null ? void 0 : engineCtx.engine) == null ? void 0 : _a.props) == null ? void 0 : _b.locale) || "zh-CN";
  const app = (_e = (_d = (_c = engineCtx == null ? void 0 : engineCtx.appHelper) == null ? void 0 : _c.utils) == null ? void 0 : _d.getApp) == null ? void 0 : _e.call(_d);
  const router = (_g = (_f = app == null ? void 0 : app.router) == null ? void 0 : _f.getRoutes) == null ? void 0 : _g.call(_f);
  const muiDatePickerAdapterLocale = (0, import_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, import_react.useEffect)(() => {
    var _a2, _b2;
    const r = (_b2 = (_a2 = engineCtx == null ? void 0 : engineCtx.appHelper) == null ? void 0 : _a2.utils) == null ? void 0 : _b2.request;
    if (r) {
      import_utils2.request.setRequest(r);
    }
  }, [(_i = (_h = engineCtx == null ? void 0 : engineCtx.appHelper) == null ? void 0 : _h.utils) == null ? void 0 : _i.request]);
  import_utils.locales.init(import_reservationConstants.PISELL_RESERVATION_PAGE_LOCALES, engineLocale);
  const resourceBoardData = (0, import_usePisellReservationResourceTableData.usePisellReservationResourceTableData)(isInternalListData);
  const gridBookingData = (0, import_usePisellReservationBookingData.usePisellReservationBookingData)(isInternalListData, {
    listPageSize: 50,
    getInitialSearchParams: import_usePisellReservationBookingData.getGridTableBookingSearchParams,
    /**
     * 必须为 false：与 `floorDayBookingData` 两路并发开 `osServer` 时，宿主侧常共用一个
     * booking 订阅槽或同 URL 请求互 abort，平面图那路 HTTP/推送会被挤掉，表现为 floor map 无预约。
     * 表格只信 HTTP；实时合并以 `floorDayBookingData`（带 form_record_ids）为准。
     */
    subscribeRealtimePush: true
  });
  const { baseFloorConfig, floorPlanRemoteId, setRemoteFloorPlanView } = (0, import_useReservationFloorPlan.useReservationFloorPlan)({
    resolvedFloorPlanId,
    effectiveFloorPlanCode,
    gridDataSourceKey,
    floorMapConfigFromProp: floorMapProp == null ? void 0 : floorMapProp.floorMapConfig,
    engineLocale
  });
  const floorConfigForBindings = (0, import_react.useMemo)(
    () => (floorMapProp == null ? void 0 : floorMapProp.floorMapConfig) ?? baseFloorConfig,
    [floorMapProp == null ? void 0 : floorMapProp.floorMapConfig, baseFloorConfig]
  );
  const floorBoundFormRecordIds = (0, import_react.useMemo)(
    () => (0, import_floorMapBoundRecordIds.sceneElementsToBoundFormRecordIds)(
      floorConfigForBindings.sceneElements,
      gridDataSourceKey
    ),
    [floorConfigForBindings.sceneElements, gridDataSourceKey]
  );
  const floorBookingResourceReady = isInternalListData && !resourceBoardData.loading;
  const floorBookingExtraParams = (0, import_react.useMemo)(
    () => ({ form_record_ids: floorBoundFormRecordIds }),
    [floorBoundFormRecordIds]
  );
  const floorDayBookingData = (0, import_usePisellReservationBookingData.usePisellReservationBookingData)(
    floorBookingResourceReady,
    { listPageSize: 999, extraRequestParams: floorBookingExtraParams }
  );
  const _getRelationTables = (0, import_ahooks.useRequest)(import_serve.getRelationTables);
  const bookingPerspectiveParams = (0, import_react.useMemo)(
    () => ({ relationTables: _getRelationTables.data }),
    [_getRelationTables.data]
  );
  const bookingPerspective = (0, import_useBookingPerspective.useBookingPerspective)(bookingPerspectiveParams);
  const runtimeContext = (0, import_react.useMemo)(
    () => ({
      refresh: () => {
        resourceBoardData.refresh();
        gridBookingData.refresh();
        floorDayBookingData.refresh();
      },
      refreshAsync: async () => {
        await Promise.all([
          resourceBoardData.refreshAsync(),
          gridBookingData.refreshAsync(),
          floorDayBookingData.refreshAsync()
        ]);
      },
      currentPerspective: "monitor"
    }),
    [
      resourceBoardData.refresh,
      resourceBoardData.refreshAsync,
      gridBookingData.refresh,
      gridBookingData.refreshAsync,
      floorDayBookingData.refresh,
      floorDayBookingData.refreshAsync
    ]
  );
  const bookingChildProps = (0, import_react.useMemo)(() => {
    const build = bookingPerspective.getChildComponentProps;
    return build ? build(runtimeContext) : {};
  }, [bookingPerspective, runtimeContext]);
  const {
    internalSchedule,
    setInternalSchedule,
    schedule,
    debouncedSchedule,
    flushCommittedSchedule,
    queueCommittedSchedule
  } = (0, import_useReservationScheduleDebounced.useReservationScheduleDebounced)({
    scheduleValueProp
  });
  const prevCommittedDateRef = (0, import_react.useRef)(null);
  const { salesResourceBookings, salesTimelineHighlights } = (0, import_useReservationSalesHostData.useReservationSalesHostData)({
    isInternalListData,
    pisellosRef,
    hasPisellosGetModule,
    debouncedSchedule,
    resourceBoardLoading: resourceBoardData.loading,
    floorDayBookingLoading: floorDayBookingData.loading,
    floorDayBookingData: floorDayBookingData.data,
    scheduleDate: schedule.date,
    timeNavigatorPropsProp
  });
  const tables = (0, import_react.useMemo)(
    () => (0, import_reservationTablesMerge.buildReservationMergedTableRows)({
      dataSourcesProp,
      gridDataSourceKey,
      isInternalListData,
      resourceList: resourceBoardData.data,
      floorDayBookingList: floorDayBookingData.data,
      schedule,
      dataProp,
      salesResourceBookings
    }),
    [
      dataSourcesProp,
      gridDataSourceKey,
      isInternalListData,
      resourceBoardData.data,
      floorDayBookingData.data,
      salesResourceBookings,
      (0, import_dayjs.default)(schedule.date).isValid() ? (0, import_dayjs.default)(schedule.date).startOf("day").valueOf() : 0,
      schedule.at != null && (0, import_dayjs.default)(schedule.at).isValid() ? (0, import_dayjs.default)(schedule.at).valueOf() : 0,
      dataProp
    ]
  );
  const debouncedScheduleKey = (0, import_react.useMemo)(
    () => `${(0, import_dayjs.default)(debouncedSchedule.date).startOf("day").valueOf()}_${(0, import_dayjs.default)(
      debouncedSchedule.at
    ).valueOf()}`,
    [debouncedSchedule.date, debouncedSchedule.at]
  );
  (0, import_react.useEffect)(() => {
    if (!(0, import_dayjs.default)(debouncedSchedule.date).isValid() || !(0, import_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, import_react.useRef)(
    (0, import_reservationDataUtils.readBodyViewFromStorageKey)(bodyViewStorageKey)
  );
  const floorMapLayoutRef = (0, import_react.useRef)(null);
  const [followWallClock, setFollowWallClock] = (0, import_react.useState)(true);
  const [isNewReservationModalOpen, setIsNewReservationModalOpen] = (0, import_react.useState)(false);
  const newReservationRoutes = (0, import_useNewReservationRoutesFromEngine.useNewReservationRoutesFromEngine)(router);
  const searchParamsRefControlled = (0, import_react.useRef)(searchParamsProp);
  (0, import_react.useEffect)(() => {
    searchParamsRefControlled.current = searchParamsProp;
  }, [searchParamsProp]);
  const onSearchRef = (0, import_react.useRef)(onSearchProp);
  const onScheduleChangeRef = (0, import_react.useRef)(onScheduleChange);
  (0, import_react.useEffect)(() => {
    onSearchRef.current = onSearchProp;
    onScheduleChangeRef.current = onScheduleChange;
  });
  (0, import_react.useEffect)(() => {
    var _a2;
    if (isInternalListData) {
      const d = debouncedSchedule.date;
      const prev = prevCommittedDateRef.current;
      if (prev != null) {
        const dateChanged = !d.startOf("day").isSame(prev.startOf("day"), "day");
        if (dateChanged) {
          floorDayBookingData.patchSearchParams(
            (prevParams) => (0, import_reservationDataUtils.mergeSearchParamsBookingWindow)(
              prevParams,
              d
            )
          );
        }
      }
      prevCommittedDateRef.current = d;
    }
    if (bodyViewRef.current === "floorMap" && !isInternalListData) {
      (_a2 = onSearchRef.current) == null ? void 0 : _a2.call(onSearchRef, {
        ...searchParamsRefControlled.current ?? {},
        reservationDate: debouncedSchedule.date.toISOString(),
        reservationAt: debouncedSchedule.at.toISOString()
      });
    }
  }, [
    debouncedSchedule,
    isInternalListData,
    floorDayBookingData.patchSearchParams
  ]);
  const handleScheduleChange = (0, import_react.useCallback)(
    (next) => {
      setFollowWallClock(false);
      if (scheduleValueProp === void 0) {
        setInternalSchedule(next);
      }
      onScheduleChange == null ? void 0 : onScheduleChange(next);
      queueCommittedSchedule(next);
    },
    [
      scheduleValueProp,
      onScheduleChange,
      setFollowWallClock,
      queueCommittedSchedule
    ]
  );
  const dataSources = (0, import_react.useMemo)(() => {
    return {
      ...dataSourcesProp,
      [gridDataSourceKey]: tables
    };
  }, [gridDataSourceKey, tables, dataSourcesProp]);
  const showVenueHudDock = (0, import_react.useMemo)(
    () => floorMapHudTableDrawer && (hudDrawerOpen || (0, import_ReservationFloorMapHud.reservationFloorMapHudSeatStatsTotal)(hudMapItems, dataSources) > 0),
    [floorMapHudTableDrawer, hudDrawerOpen, hudMapItems, dataSources]
  );
  const handleOpenHudTableDrawer = (0, import_react.useCallback)(() => {
    const boundTableRows = (0, import_reservationHudTableRows.filterReservationRowsBoundOnCanvas)(
      hudItemsRef.current,
      dataSources,
      gridDataSourceKey
    );
    const resourceIdSet = new Set(
      boundTableRows.map((r) => String(r.id)).filter(Boolean)
    );
    const parentSnapshot = (0, import_hudDrawerLocalListQuery.cloneHudDrawerSearchParams)(
      isInternalListData ? floorDayBookingData.searchParams : searchParamsProp ?? {}
    );
    (0, import_hudDrawerLocalListQuery.stripHudDrawerBookingDateQuickFilter)(parentSnapshot);
    hudDrawerSearchParamsOpenSnapshotRef.current = parentSnapshot;
    setHudDrawerLocalSearchParams(parentSnapshot);
    setHudDrawerResourceIds(resourceIdSet);
    setHudDrawerListPagination({
      pageNumber: 1,
      pageSize: import_reservationConstants.PISELL_RESERVATION_HUD_LOCAL_PAGE_SIZE
    });
    setHudDrawerOpen(true);
  }, [
    dataSources,
    gridDataSourceKey,
    isInternalListData,
    floorDayBookingData.searchParams,
    searchParamsProp
  ]);
  const closeHudTableDrawer = (0, import_react.useCallback)(() => {
    setHudDrawerOpen(false);
    setHudDrawerResourceIds(null);
    setHudDrawerLocalSearchParams({});
    setHudDrawerListPagination({
      pageNumber: 1,
      pageSize: import_reservationConstants.PISELL_RESERVATION_HUD_LOCAL_PAGE_SIZE
    });
  }, []);
  (0, import_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]);
  const hudDrawerDisplayRows = (0, import_react.useMemo)(() => {
    if (!floorMapHudTableDrawer || !hudDrawerOpen || !hudDrawerResourceIds || hudDrawerResourceIds.size === 0) {
      return [];
    }
    const source = isInternalListData ? floorDayBookingData.data : dataProp ?? [];
    const baseRows = (0, import_bookingToReservationTables.filterBookingsByResourceIds)(source, hudDrawerResourceIds);
    return (0, import_hudDrawerLocalListQuery.applyHudDrawerLocalListQuery)(baseRows, 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, import_react.useEffect)(() => {
    if (hudDrawerListPagination.pageNumber <= hudDrawerMaxPage) return;
    setHudDrawerListPagination((p) => ({ ...p, pageNumber: hudDrawerMaxPage }));
  }, [hudDrawerMaxPage, hudDrawerListPagination.pageNumber]);
  const hudDrawerPagedRows = (0, import_react.useMemo)(() => {
    const { pageNumber, pageSize } = hudDrawerListPagination;
    const start = (pageNumber - 1) * pageSize;
    return hudDrawerDisplayRows.slice(start, start + pageSize);
  }, [hudDrawerDisplayRows, hudDrawerListPagination]);
  const hudDrawerToolBar = (0, import_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 {
      ...base,
      toolbarDensity: "compact",
      /** 日程已由页顶/ floorDay 决定，抽屉内日期快筛无意义 */
      quickFilter: false,
      className: (0, import_classnames.default)(
        baseClass,
        "pisell-record-board-toolbar--narrow-stack"
      )
    };
  }, [bookingChildProps.toolBar]);
  const hudDrawerLoading = isInternalListData ? floorDayBookingData.loading : loadingProp ?? false;
  const hudDrawerBookingPagination = (0, import_react.useMemo)(
    () => ({
      pageNumber: hudDrawerListPagination.pageNumber,
      pageSize: hudDrawerListPagination.pageSize
    }),
    [hudDrawerListPagination.pageNumber, hudDrawerListPagination.pageSize]
  );
  const hudDrawerOnSearch = (0, import_react.useCallback)((params) => {
    setHudDrawerListPagination((p) => ({ ...p, pageNumber: 1 }));
    setHudDrawerLocalSearchParams(
      (prev) => (0, import_hudDrawerLocalListQuery.mergeHudDrawerSearchParams)(prev, params)
    );
  }, []);
  const hudDrawerOnReset = (0, import_react.useCallback)(() => {
    setHudDrawerListPagination((p) => ({ ...p, pageNumber: 1 }));
    setHudDrawerLocalSearchParams(
      (0, import_hudDrawerLocalListQuery.cloneHudDrawerSearchParams)(hudDrawerSearchParamsOpenSnapshotRef.current)
    );
  }, []);
  const hudDrawerOnPageChange = (0, import_react.useCallback)(
    (pageNumber, pageSize) => {
      setHudDrawerListPagination({ pageNumber, pageSize });
    },
    []
  );
  const hudRecordBoardPaginationConfig = (0, import_react.useMemo)(
    () => ({
      showSizeChanger: true,
      pageSizeOptions: ["10", "20", "50", "100"]
    }),
    []
  );
  const renderItemByKind = (0, import_react.useMemo)(
    () => (0, import_reservationCards.getReservationRenderItemByKind)(dataSources),
    [dataSources]
  );
  const reservationFloorMapViewportOverlay = (0, import_react.useCallback)(
    (args) => {
      const items = args.items;
      hudItemsRef.current = items;
      if (floorMapHudTableDrawer) {
        return /* @__PURE__ */ import_react.default.createElement(ReservationHudMapItemsSync, { items, setItems: setHudMapItems });
      }
      return /* @__PURE__ */ import_react.default.createElement(
        import_ReservationFloorMapHud.ReservationFloorMapHud,
        {
          items,
          dataSources: args.dataSources,
          interactive: false
        }
      );
    },
    [floorMapHudTableDrawer]
  );
  const isFloorModeControlled = (floorMapProp == null ? void 0 : floorMapProp.mode) !== void 0;
  const [mapEditInternal, setMapEditInternal] = (0, import_react.useState)(false);
  const effectiveMapMode = (floorMapProp == null ? void 0 : floorMapProp.mode) ?? (mapEditInternal ? "edit" : "read");
  const {
    bookingDetailOpen,
    bookingDetailRaw,
    bookingDetailRow,
    bookingDetailSceneName,
    closeBookingDetailModal,
    floorMapItemClickBefore
  } = (0, import_useFloorMapBookingInteraction.useFloorMapBookingInteraction)({
    engineCtx,
    onFloorMapBookingClick
  });
  const floorMapMerged = (0, import_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 ?? [];
  const loading = isInternalListData ? gridBookingData.loading : loadingProp ?? false;
  const loadingShown = (0, import_useReservationLoadingShownDebounced.useReservationLoadingShownDebounced)(loading);
  const total = isInternalListData ? gridBookingData.total : totalProp ?? 0;
  const pagination = isInternalListData ? gridBookingData.pagination : paginationProp ?? { pageNumber: 1, pageSize: 50 };
  const onPageChange = isInternalListData ? gridBookingData.onPageChange : onPageChangeProp;
  const searchParams = isInternalListData ? gridBookingData.searchParams : searchParamsProp ?? {};
  const onGridBookingSearch = (0, import_react.useCallback)(
    (params) => {
      gridBookingData.onSearch((0, import_reservationDataUtils.mergeGridBookingSearchParams)(params));
    },
    [gridBookingData.onSearch]
  );
  const onSearch = isInternalListData ? onGridBookingSearch : onSearchProp;
  const onReset = isInternalListData ? gridBookingData.onReset : onResetProp;
  const handleRouteJump = (0, import_ahooks.useMemoizedFn)((routePath) => {
    var _a2, _b2;
    if (!routePath) return;
    setIsNewReservationModalOpen(false);
    (_b2 = (_a2 = app == null ? void 0 : app.history) == null ? void 0 : _a2.push) == null ? void 0 : _b2.call(_a2, routePath);
  });
  const handleOpenNewReservationModal = (0, import_ahooks.useMemoizedFn)(() => {
    if (newReservationRoutes.length === 1) {
      handleRouteJump(newReservationRoutes[0].router);
      return;
    }
    setIsNewReservationModalOpen(true);
  });
  const handleCloseNewReservationModal = (0, import_ahooks.useMemoizedFn)(() => {
    setIsNewReservationModalOpen(false);
  });
  (0, import_react.useEffect)(() => {
    if (!followWallClock) return;
    const tick = () => {
      var _a2;
      const now = (0, import_dayjs.default)();
      const next = {
        date: now.startOf("day"),
        at: now
      };
      if (scheduleValueProp === void 0) {
        setInternalSchedule(next);
      }
      (_a2 = onScheduleChangeRef.current) == null ? void 0 : _a2.call(onScheduleChangeRef, next);
      flushCommittedSchedule(next);
    };
    tick();
    const id = window.setInterval(tick, 3e4);
    return () => window.clearInterval(id);
  }, [followWallClock, scheduleValueProp, flushCommittedSchedule]);
  const defaultScheduleEnd = (0, import_react.useMemo)(
    () => /* @__PURE__ */ import_react.default.createElement(
      import_PisellReservationSubcomponents.PisellReservationScheduleEndActions,
      {
        onNewReservation: handleOpenNewReservationModal
      }
    ),
    [handleOpenNewReservationModal]
  );
  const effectiveScheduleEndSlot = (0, import_react.useMemo)(() => {
    const slotNode = scheduleEndSlotProp ?? defaultScheduleEnd;
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        onClickCapture: (event) => {
          const target = event.target;
          if (!(target == null ? void 0 : target.closest(".pisell-reservation-new-btn"))) return;
          event.preventDefault();
          event.stopPropagation();
          handleOpenNewReservationModal();
        }
      },
      slotNode
    );
  }, [scheduleEndSlotProp, defaultScheduleEnd, handleOpenNewReservationModal]);
  const bookingToolBar = bookingChildProps.toolBar;
  const loadReservationDensity = (0, import_react.useCallback)(
    async ({
      referenceDate,
      stepMinutes
    }) => {
      const slotCount = (0, import_reservationDensity.reservationTimelineAxisSlotCount)(
        referenceDate,
        stepMinutes,
        (timeNavigatorPropsProp == null ? void 0 : timeNavigatorPropsProp.range) ?? import_reservationConstants.RESERVATION_TIMELINE_BUSINESS_RANGE
      );
      if (salesTimelineHighlights != null && salesTimelineHighlights.length > 0) {
        return (0, import_reservationDensity.fitTimelineHighlightsToSlotCount)(
          salesTimelineHighlights,
          slotCount
        );
      }
      const densityRows = isInternalListData ? floorDayBookingData.data : data;
      return (0, import_reservationDensity.computeReservationDensityBuckets)(
        densityRows,
        referenceDate,
        stepMinutes
      );
    },
    [
      isInternalListData,
      floorDayBookingData.data,
      data,
      salesTimelineHighlights,
      (_j = timeNavigatorPropsProp == null ? void 0 : timeNavigatorPropsProp.range) == null ? void 0 : _j.start,
      (_k = timeNavigatorPropsProp == null ? void 0 : timeNavigatorPropsProp.range) == null ? void 0 : _k.end
    ]
  );
  const toolBarMerged = (0, import_react.useMemo)(() => {
    const {
      tabs: extraTabs,
      topRight: topRightProp,
      bottomLeft: bottomLeftProp,
      ...restToolbar
    } = toolBarProp ?? {};
    return {
      ...bookingToolBar ?? {},
      ...restToolbar,
      tabs: /* @__PURE__ */ import_react.default.createElement(
        import_PisellReservationSubcomponents.PisellReservationToolbarTabs,
        {
          extraTabs,
          schedule,
          onScheduleChange: handleScheduleChange,
          scheduleProps: schedulePropsProp,
          timeNavigatorProps: timeNavigatorPropsProp,
          scheduleStartSlot: scheduleStartSlotProp ?? /* @__PURE__ */ import_react.default.createElement(import_PisellReservationSubcomponents.ReservationDefaultScheduleStart, null),
          scheduleEndSlot: effectiveScheduleEndSlot,
          followWallClock,
          onFollowWallClockToggle: () => setFollowWallClock((v) => !v),
          onTimeNavigatorUserInteraction: () => setFollowWallClock(false),
          loadDensity: loadReservationDensity
        }
      ),
      topRight: /* @__PURE__ */ import_react.default.createElement(import_PisellReservationSubcomponents.ReservationGridTopRight, { extra: topRightProp }),
      bottomLeft: bottomLeftProp ?? null
    };
  }, [
    bookingToolBar,
    toolBarProp,
    schedule,
    handleScheduleChange,
    scheduleStartSlotProp,
    effectiveScheduleEndSlot,
    followWallClock,
    timeNavigatorPropsProp,
    schedulePropsProp,
    loadReservationDensity
  ]);
  const recordBoardGrid = (0, import_react.useMemo)(() => {
    return bookingChildProps.grid;
  }, [bookingChildProps.grid]);
  const hudDrawerGrid = (0, import_react.useMemo)(() => {
    const g = recordBoardGrid;
    if (g == null || typeof g !== "object") {
      return { size: "small" };
    }
    return { ...g, size: "small" };
  }, [recordBoardGrid]);
  const fillHeight = ((_l = recordBoardGrid == null ? void 0 : recordBoardGrid.scroll) == null ? void 0 : _l.autoCalc) ?? true;
  return /* @__PURE__ */ import_react.default.createElement(
    import_date_picker.LocalizationProvider,
    {
      dateAdapter: import_AdapterDayjs.AdapterDayjs,
      adapterLocale: muiDatePickerAdapterLocale
    },
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)("pisell-reservation-page", className),
        style
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_materials.PisellRecordBoard,
        {
          ...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__ */ import_react.default.createElement(import_materials.PisellRecordBoard.ShellFrame, null, /* @__PURE__ */ import_react.default.createElement(import_PisellReservationSubcomponents.RecordBoardBodyViewCapture, { bodyViewRef }), /* @__PURE__ */ import_react.default.createElement(
          import_PisellReservationSubcomponents.ScheduleSyncOnFloorEnter,
          {
            schedule,
            isInternalListData,
            patchSearchParams: floorDayBookingData.patchSearchParams
          }
        ), /* @__PURE__ */ import_react.default.createElement(import_materials.PisellRecordBoard.GridLayout, null), /* @__PURE__ */ import_react.default.createElement(import_materials.PisellRecordBoard.FloorMap, null))
      ),
      /* @__PURE__ */ import_react.default.createElement(
        import_materials.PisellModal,
        {
          platform: "pc",
          open: isNewReservationModalOpen,
          title: import_utils.locales.getText(import_reservationConstants.I18N_NEW_MODAL_TITLE),
          onCancel: handleCloseNewReservationModal,
          maskClosable: true,
          footer: null,
          width: 520,
          wrapClassName: "pisell-reservation-new-modal-wrap",
          destroyOnClose: true
        },
        /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-new-modal-placeholder" }, newReservationRoutes.length > 0 ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-new-modal-route-list" }, newReservationRoutes.map((routeItem) => /* @__PURE__ */ import_react.default.createElement(
          "button",
          {
            key: `${routeItem.router}-${routeItem.pageName}`,
            type: "button",
            className: "pisell-reservation-new-modal-route-item",
            onClick: () => handleRouteJump(routeItem.router)
          },
          /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-new-modal-route-name" }, routeItem.pageName),
          /* @__PURE__ */ import_react.default.createElement(
            import_materials.Icon,
            {
              type: "icon-right-arrow",
              className: "pisell-reservation-new-modal-route-arrow"
            }
          )
        ))) : /* @__PURE__ */ import_react.default.createElement("p", { className: "pisell-reservation-new-modal-empty" }, import_utils.locales.getText(import_reservationConstants.I18N_NEW_MODAL_PLACEHOLDER)))
      ),
      /* @__PURE__ */ import_react.default.createElement(
        import_ReservationBookingDetailModal.ReservationBookingDetailModal,
        {
          open: bookingDetailOpen,
          onClose: closeBookingDetailModal,
          raw: bookingDetailRaw,
          tableRow: bookingDetailRow,
          sceneElementName: bookingDetailSceneName
        }
      ),
      fab ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-fab" }, fab) : null,
      showVenueHudDock ? /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: (0, import_classnames.default)(
            "pisell-reservation-hud-dock",
            hudDrawerOpen && "pisell-reservation-hud-dock--expanded"
          ),
          role: "dialog",
          "aria-modal": "false",
          "aria-expanded": hudDrawerOpen,
          "aria-label": import_utils.locales.getText(import_reservationConstants.I18N_HUD_TABLE_DRAWER_TITLE)
        },
        /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-hud-dock-header" }, /* @__PURE__ */ import_react.default.createElement(
          import_ReservationFloorMapHud.ReservationFloorMapHudTitleBar,
          {
            items: hudMapItems,
            dataSources,
            actionMode: hudDrawerOpen ? "collapse" : "expand",
            onAction: hudDrawerOpen ? closeHudTableDrawer : handleOpenHudTableDrawer,
            embedded: true,
            className: "pisell-reservation-hud-dock-title-inner"
          }
        )),
        hudDrawerOpen ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-hud-dock-body" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-hud-dock-record-board" }, /* @__PURE__ */ import_react.default.createElement(
          import_materials.PisellRecordBoard,
          {
            columnVisibilityStorageKey: import_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__ */ import_react.default.createElement(import_materials.PisellRecordBoard.ShellFrame, null, /* @__PURE__ */ import_react.default.createElement(import_materials.PisellRecordBoard.GridLayout, null))
        ))) : null
      ) : null
    )
  );
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PisellReservationCore
});
