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/floorMap/useReservationFloorMapMerged.tsx
var useReservationFloorMapMerged_exports = {};
__export(useReservationFloorMapMerged_exports, {
  useReservationFloorMapMerged: () => useReservationFloorMapMerged
});
module.exports = __toCommonJS(useReservationFloorMapMerged_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_pisellProResourcePickerModal = require("../../pisellProResourcePickerModal");
var import_pisellProResourcePickerModal2 = require("../../pisellProResourcePickerModal");
var import_floorPlanApi = require("./floorPlanApi");
var import_reservationMock = require("./reservationMock");
var import_PisellReservationSubcomponents = require("../components/PisellReservationSubcomponents");
var I18N_FLOOR_MAP_DATA_SOURCE_LABEL = "pisell-reservation.floor-map.data-source-label";
var TEMP_DISABLE_RESERVATION_VIEWPORT_PERSIST = true;
function useReservationFloorMapMerged(params) {
  const {
    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 = false,
    readModeSelectedItemId: readModeSelectedItemIdParam,
    editTopBarPhoneLayout: editTopBarPhoneLayoutParam,
    appearanceMode,
    onToggleAppearanceMode
  } = params;
  return (0, import_react.useMemo)(() => {
    var _a;
    const labels = {
      [gridDataSourceKey]: import_utils.locales.getText(I18N_FLOOR_MAP_DATA_SOURCE_LABEL)
    };
    const forms = {
      [gridDataSourceKey]: (0, import_reservationMock.getReservationDataSourceFormColumns)()
    };
    const { getMergedItemWrapperStyle, ...floorRest } = floorMapProp ?? {};
    const prevOnSave = floorRest.onSave;
    const persistTargetId = floorPlanRemoteId ?? resolvedFloorPlanId;
    const persistApi = persistTargetId != null && Number.isFinite(persistTargetId) && Math.floor(persistTargetId) === persistTargetId && persistTargetId > 0;
    const onSaveWithApi = (0, import_materials.wrapFloorMapOnSaveWithRemotePersist)({
      canPersist: persistApi,
      persistTargetId: persistTargetId ?? 0,
      persist: (id, config) => (0, import_floorPlanApi.saveViewConfigToShopFloorPlan)(id, config, {
        canvasWidth: floorPlanCanvasWidth,
        canvasHeight: floorPlanCanvasHeight,
        code: effectiveFloorPlanCode,
        name: floorPlanName,
        sort: floorPlanSort,
        status: floorPlanStatus,
        putFloorPlan: putFloorPlan != null ? (planId, body) => putFloorPlan(
          planId,
          body
        ) : void 0
      }),
      setRemoteFloorPlanView,
      onFloorPlanPersisted,
      prevOnSave,
      onPersistError: import_floorPlanApi.toastFloorPlanSaveError
    });
    const mergedDataSources = (floorMapProp == null ? void 0 : floorMapProp.dataSources) ?? dataSources;
    const reservationViewportNamespace = effectiveFloorPlanCode ? `reservation-code:${effectiveFloorPlanCode}` : resolvedFloorPlanId != null ? `reservation:${resolvedFloorPlanId}` : "reservation:default";
    const reservationDefaultMapLayerBackgroundColor = appearanceMode === "light" ? "#e8e8e8" : void 0;
    return {
      mapLayer: {
        showGrid: true,
        snapStep: 1,
        ...reservationDefaultMapLayerBackgroundColor == null ? {} : {
          backgroundColor: reservationDefaultMapLayerBackgroundColor
        },
        ...floorRest.mapLayer
      },
      cellSize: floorRest.cellSize ?? 10,
      itemUnit: floorRest.itemUnit ?? "pixel",
      dataSourceLabels: labels,
      dataSourceFormColumns: forms,
      ...floorRest,
      floorMapConfig: floorRest.floorMapConfig ?? baseFloorConfig,
      dataSources: mergedDataSources,
      renderItemByKind: (floorMapProp == null ? void 0 : floorMapProp.renderItemByKind) ?? renderItemByKind,
      appearanceMode,
      mode: effectiveMapMode,
      toolbarShowSave: floorRest.toolbarShowSave ?? false,
      showDataSourceRecordFormBlock: floorRest.showDataSourceRecordFormBlock ?? false,
      zoom: {
        defaultScale: 1,
        min: 0.4,
        max: 2.2,
        step: 0.1,
        ...floorRest.zoom,
        autoFitOnMount: TEMP_DISABLE_RESERVATION_VIEWPORT_PERSIST ? true : ((_a = floorRest.zoom) == null ? void 0 : _a.autoFitOnMount) !== false
      },
      controls: {
        showZoom: true,
        showReset: true,
        showFitBounds: true,
        showGridToggle: true,
        /* dockChrome 模式已强制锚定右下，无需再传 horizontalAlign */
        ...floorRest.controls
      },
      pan: {
        enabled: true,
        /** 与 PisellFloorMapLayout `limitToBounds` 对齐：none 可一直拖动画布，不被内容包盒限制 */
        boundary: "none",
        ...floorRest.pan
      },
      onItemClick: (item, index, event) => {
        var _a2;
        floorMapItemClickBefore == null ? void 0 : floorMapItemClickBefore({
          item,
          index,
          event,
          mode: effectiveMapMode,
          dataSources: mergedDataSources
        });
        (_a2 = floorMapProp == null ? void 0 : floorMapProp.onItemClick) == null ? void 0 : _a2.call(floorMapProp, item, index, event);
      },
      getMergedItemWrapperStyle,
      onSave: onSaveWithApi,
      /**
       * 顶栏「退出编辑 / 完成」联动：
       * - 仅在 mode 由内部受控（业务自管 mapEditInternal）时注入；mode 受控走父级 onModeChange。
       * - 「完成」= 顶栏内部先调 onSave，再调 onExitEdit；「取消编辑」= 仅调 onExitEdit。
       */
      onExitEdit: floorRest.onExitEdit ?? (isFloorModeControlled ? void 0 : () => {
        setMapEditInternal(false);
      }),
      floorMapViewportOverlay: floorRest.floorMapViewportOverlay ?? reservationFloorMapViewportOverlay,
      /**
       * 场控 HUD 必须锚左下：低代码常写 `viewportOverlayPlacement: 'top-start'`，
       * 用 `??` 无法覆盖 truthy，会导致标题栏仍出现在左上。
       */
      viewportOverlayPlacement: floorMapHudTableDrawer ? "bottom-start" : floorRest.viewportOverlayPlacement,
      viewportOverlayClassName: floorRest.viewportOverlayClassName,
      canvasTabsBarTrailing: floorRest.canvasTabsBarTrailing,
      /**
       * 视口持久化：`TEMP_DISABLE_RESERVATION_VIEWPORT_PERSIST === true` 时临时关闭读写，仅首屏全览；
       * 关闭该常量后恢复「尊重业务 persist + reservationViewportNamespace」。
       */
      viewportPersist: TEMP_DISABLE_RESERVATION_VIEWPORT_PERSIST ? false : floorRest.viewportPersist,
      viewportPersistNamespace: TEMP_DISABLE_RESERVATION_VIEWPORT_PERSIST ? void 0 : floorRest.viewportPersistNamespace ?? reservationViewportNamespace,
      viewportDockToolButtons: floorRest.viewportDockToolButtons ?? /* @__PURE__ */ import_react.default.createElement(
        import_PisellReservationSubcomponents.ReservationFloorMapDockToolButtons,
        {
          appearanceMode,
          onToggleAppearanceMode
        }
      ),
      /**
       * 低代码常传 `viewportDockTrailing: false` 以隐藏 Dock 尾区（如「编辑画布」）。
       * ViewControls 用「尾槽是否存在」参与 showBar 计算：`false` 会导致无尾槽且无 zoom 时整条左下角控件消失。
       * 用空 Fragment 占位：不渲染编辑按钮，仍保留缩放/复位/fit 等 Dock 行为（与预约页默认一致）。
       */
      viewportDockTrailing: floorRest.viewportDockTrailing === false ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null) : floorRest.viewportDockTrailing ?? /* @__PURE__ */ import_react.default.createElement(
        import_PisellReservationSubcomponents.ReservationFloorMapCanvasTabsTrailing,
        {
          isFloorModeControlled,
          mapEditInternal,
          setMapEditInternal,
          floorMapLayoutRef,
          phoneLayout: editTopBarPhoneLayoutParam
        }
      ),
      readModeSelectedItemId: readModeSelectedItemIdParam ?? floorRest.readModeSelectedItemId,
      editTopBarPhoneLayout: floorRest.editTopBarPhoneLayout ?? editTopBarPhoneLayoutParam,
      /**
       * 预约平面图不做拓扑连线：禁止低代码 floorMap.enableEdges 误开四向锚点圆点。
       * 选中图元时仍可能有四角缩放手柄（布局编辑），与连线能力无关。
       */
      enableEdges: false,
      /**
       * 编辑态从画布添加资源时，使用 Pro 版资源选择 modal：顶部 PisellTabbarTemplate1，列表 Selector。
       * 通用基础 modal 已下线，由本注入承担；业务方可通过 `floorMap.renderResourcePickerModal` 显式覆盖。
       * 沿用原 floor-map 的 `area` 三级嵌套分类与卡片元信息（与下线前默认行为一致）。
       */
      renderResourcePickerModal: floorRest.renderResourcePickerModal ?? ((modalProps) => /* @__PURE__ */ import_react.default.createElement(
        import_pisellProResourcePickerModal.PisellProResourcePickerModal,
        {
          ...modalProps,
          platform: editTopBarPhoneLayoutParam ? "h5" : "pc",
          categoryConfig: (0, import_materials.getFloorMapCardPickerCategoryConfig)(),
          getSearchText: import_materials.floorMapResourcePickerRecordSearchText,
          getCardMeta: import_materials.getFloorMapResourcePickerCardMeta,
          renderFilterBar: (ctx) => /* @__PURE__ */ import_react.default.createElement(
            import_materials.PisellTabbarTemplate1,
            {
              className: "pisell-pro-resource-picker-tabbar",
              style: {
                position: "sticky",
                top: 0,
                zIndex: 10,
                padding: 6,
                background: "rgb(250, 250, 250)"
              },
              dataSource: ctx.tabbarDataSource,
              value: ctx.tabbarValue,
              onChange: ctx.onTabbarValueChange,
              onSearch: ctx.onKeywordChange,
              maxLevel: 3
            }
          )
        }
      )),
      renderPaletteViewAllModal: floorRest.renderPaletteViewAllModal ?? ((viewAllProps) => /* @__PURE__ */ import_react.default.createElement(
        import_pisellProResourcePickerModal2.PisellFloorMapPaletteViewAllModal,
        {
          ...viewAllProps,
          platform: editTopBarPhoneLayoutParam ? "h5" : "pc"
        }
      ))
    };
  }, [
    baseFloorConfig,
    dataSources,
    floorMapProp,
    floorMapHudTableDrawer,
    reservationFloorMapViewportOverlay,
    renderItemByKind,
    gridDataSourceKey,
    appearanceMode,
    effectiveMapMode,
    resolvedFloorPlanId,
    floorPlanRemoteId,
    effectiveFloorPlanCode,
    floorPlanCanvasWidth,
    floorPlanCanvasHeight,
    floorPlanName,
    floorPlanSort,
    floorPlanStatus,
    onFloorPlanPersisted,
    putFloorPlan,
    isFloorModeControlled,
    mapEditInternal,
    floorMapLayoutRef,
    onToggleAppearanceMode,
    setRemoteFloorPlanView,
    floorMapItemClickBefore,
    engineLocale,
    readModeSelectedItemIdParam,
    editTopBarPhoneLayoutParam
  ]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useReservationFloorMapMerged
});
