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_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";
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
  } = 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;
    return {
      mapLayer: {
        showGrid: true,
        backgroundColor: "#e8e8e8",
        snapStep: 1,
        ...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,
      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: ((_a = floorRest.zoom) == null ? void 0 : _a.autoFitOnMount) !== false
      },
      controls: {
        showZoom: true,
        showReset: true,
        showFitBounds: true,
        showGridToggle: true,
        horizontalAlign: "end",
        ...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,
      floorMapViewportOverlay: floorRest.floorMapViewportOverlay ?? reservationFloorMapViewportOverlay,
      /**
       * 场控 HUD 必须锚左下：低代码常写 `viewportOverlayPlacement: 'top-start'`，
       * 用 `??` 无法覆盖 truthy，会导致标题栏仍出现在左上。
       */
      viewportOverlayPlacement: floorMapHudTableDrawer ? "bottom-start" : floorRest.viewportOverlayPlacement,
      viewportOverlayClassName: floorRest.viewportOverlayClassName,
      canvasTabsBarTrailing: floorRest.canvasTabsBarTrailing,
      /**
       * 低代码常传 `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
        }
      )
    };
  }, [
    baseFloorConfig,
    dataSources,
    floorMapProp,
    floorMapHudTableDrawer,
    reservationFloorMapViewportOverlay,
    renderItemByKind,
    gridDataSourceKey,
    effectiveMapMode,
    resolvedFloorPlanId,
    floorPlanRemoteId,
    effectiveFloorPlanCode,
    floorPlanCanvasWidth,
    floorPlanCanvasHeight,
    floorPlanName,
    floorPlanSort,
    floorPlanStatus,
    onFloorPlanPersisted,
    putFloorPlan,
    isFloorModeControlled,
    mapEditInternal,
    floorMapLayoutRef,
    setRemoteFloorPlanView,
    floorMapItemClickBefore,
    engineLocale
  ]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useReservationFloorMapMerged
});
