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/pisellTopology/floorPlan/useTopologyFloorMapMerged.tsx
var useTopologyFloorMapMerged_exports = {};
__export(useTopologyFloorMapMerged_exports, {
  useTopologyFloorMapMerged: () => useTopologyFloorMapMerged
});
module.exports = __toCommonJS(useTopologyFloorMapMerged_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_topologyFloorPlanApi = require("./topologyFloorPlanApi");
var import_topologyRenderItems = require("../topologyRenderItems");
var import_TopologyOverviewHud = require("../TopologyOverviewHud");
var import_topologyFloorPlanConstants = require("../topologyFloorPlanConstants");
var import_TopologyFloorMapEditToggle = require("../components/TopologyFloorMapEditToggle");
function useTopologyFloorMapMerged(params) {
  const {
    baseFloorConfig,
    dataSources,
    devices,
    mode,
    mapEditInternal,
    setMapEditInternal,
    floorMapLayoutRef,
    forceEditFromProps,
    resolvedFloorPlanId,
    floorPlanRemoteId,
    effectiveFloorPlanCode,
    floorPlanCanvasWidth,
    floorPlanCanvasHeight,
    floorPlanName,
    floorPlanSort,
    floorPlanStatus,
    onFloorPlanPersisted,
    putFloorPlan,
    prevOnSave,
    overviewHud,
    setRemoteFloorPlanView,
    className,
    style
  } = params;
  return (0, import_react.useMemo)(() => {
    const devicesById = new Map(devices.map((d) => [String(d.id), d]));
    const persistTargetId = floorPlanRemoteId ?? resolvedFloorPlanId;
    const canPersist = persistTargetId != null && Number.isFinite(persistTargetId) && Math.floor(persistTargetId) === persistTargetId && persistTargetId > 0;
    const onSaveWithApi = (0, import_materials.wrapFloorMapOnSaveWithRemotePersist)({
      canPersist,
      persistTargetId: persistTargetId ?? 0,
      persist: (id, config) => (0, import_topologyFloorPlanApi.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_topologyFloorPlanApi.toastFloorPlanSaveError
    });
    const namespace = `topology:${effectiveFloorPlanCode || import_topologyFloorPlanConstants.PISELL_TOPOLOGY_FLOOR_PLAN_CODE}`;
    const overlay = overviewHud === false ? void 0 : (args) => typeof overviewHud === "undefined" || overviewHud === void 0 ? /* @__PURE__ */ import_react.default.createElement(
      import_TopologyOverviewHud.TopologyOverviewHud,
      {
        ...args,
        edges: baseFloorConfig.edges
      }
    ) : overviewHud;
    return {
      className,
      style: {
        width: "100%",
        height: "100%",
        minHeight: 0,
        flex: 1,
        ...style
      },
      items: [],
      renderItem: () => null,
      floorMapConfig: baseFloorConfig,
      dataSources,
      mode,
      itemUnit: "pixel",
      /** Topology 需要连线渲染与编辑；其它通用画布场景（reservation 等）默认关闭 */
      enableEdges: true,
      toolbarShowSave: true,
      onSave: onSaveWithApi,
      renderItemByKind: (0, import_topologyRenderItems.getTopologyRenderItemByKind)(devicesById),
      floorMapViewportOverlay: overlay,
      viewportOverlayPlacement: "top-start",
      viewportPersistNamespace: namespace,
      controls: {
        showZoom: true,
        showFitBounds: true,
        showReset: true,
        showGridToggle: true,
        horizontalAlign: "end"
      },
      onExitEdit: forceEditFromProps ? void 0 : () => {
        setMapEditInternal(false);
      },
      viewportDockTrailing: /* @__PURE__ */ import_react.default.createElement(
        import_TopologyFloorMapEditToggle.TopologyFloorMapEditToggle,
        {
          mapEditInternal,
          setMapEditInternal,
          floorMapLayoutRef,
          forceEditMode: forceEditFromProps
        }
      ),
      pan: { enabled: true },
      zoom: { autoFitOnMount: true, min: 0.25, max: 2 }
    };
  }, [
    baseFloorConfig,
    dataSources,
    devices,
    mode,
    mapEditInternal,
    setMapEditInternal,
    floorMapLayoutRef,
    forceEditFromProps,
    resolvedFloorPlanId,
    floorPlanRemoteId,
    effectiveFloorPlanCode,
    floorPlanCanvasWidth,
    floorPlanCanvasHeight,
    floorPlanName,
    floorPlanSort,
    floorPlanStatus,
    onFloorPlanPersisted,
    putFloorPlan,
    prevOnSave,
    overviewHud,
    setRemoteFloorPlanView,
    className,
    style
  ]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useTopologyFloorMapMerged
});
