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/components/pisellFloorMapLayout/utils/floorMapOverviewLayout.ts
var floorMapOverviewLayout_exports = {};
__export(floorMapOverviewLayout_exports, {
  buildFloorMapOverviewLayout: () => buildFloorMapOverviewLayout
});
module.exports = __toCommonJS(floorMapOverviewLayout_exports);
var import_floorMapConfigMerge = require("./floorMapConfigMerge");
var import_floorMapCanvasStage = require("./floorMapCanvasStage");
var import_layoutMeasurements = require("./layoutMeasurements");
var import_floorMapViewportPersistence = require("../hooks/floorMapViewportPersistence");
var import_mergeCanvasesForTabs = require("./mergeCanvasesForTabs");
var import_floorMapLayoutConstants = require("../floorMapLayoutConstants");
function buildFloorMapOverviewLayout(params) {
  const { config, globalMapLayer, cellSize, itemUnit, areaGap } = params;
  const enriched = (0, import_mergeCanvasesForTabs.mergeCanvasesForTabs)(config);
  const enabledOrdered = enriched.filter((c) => c.enabled).sort((a, b) => a.order - b.order);
  const stageList = enabledOrdered.map((canvas) => {
    const items = (0, import_floorMapConfigMerge.mergeCanvasItems)(canvas.id, config, cellSize);
    const effectiveMapLayer = canvas.mapLayer ? { ...globalMapLayer ?? {}, ...canvas.mapLayer } : globalMapLayer;
    const boundingPadding = (effectiveMapLayer == null ? void 0 : effectiveMapLayer.boundingPadding) ?? import_floorMapViewportPersistence.DEFAULT_BOUNDING_PADDING;
    const itemGap = (0, import_layoutMeasurements.gapToPx)(effectiveMapLayer == null ? void 0 : effectiveMapLayer.gap);
    const stage = (0, import_floorMapCanvasStage.computeFloorMapContentStage)({
      items,
      cellSize,
      itemGap,
      itemUnit,
      boundingPadding,
      preferPixelBoundingBox: true
    });
    return {
      canvasId: canvas.id,
      items,
      contentWidth: stage.contentWidth,
      contentHeight: stage.contentHeight,
      contentOffsetX: stage.contentOffsetX,
      contentOffsetY: stage.contentOffsetY,
      cellSize
    };
  });
  const titleBandHeight = import_floorMapLayoutConstants.FLOOR_MAP_OVERVIEW_TITLE_BAND_HEIGHT;
  const pack = (0, import_floorMapCanvasStage.packCanvasesIntoShelves)(
    stageList.map((s) => ({
      width: s.contentWidth,
      /** 装箱高度 = 标题带 + 画布内容，使相邻区块 gap 为标题留出空间 */
      height: s.contentHeight + titleBandHeight
    })),
    areaGap
  );
  const areas = stageList.map((s, i) => {
    var _a, _b;
    return {
      ...s,
      x: ((_a = pack.positions[i]) == null ? void 0 : _a.x) ?? 0,
      y: ((_b = pack.positions[i]) == null ? void 0 : _b.y) ?? 0,
      titleBandHeight
    };
  });
  return {
    areas,
    totalWidth: pack.totalWidth,
    totalHeight: pack.totalHeight
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildFloorMapOverviewLayout
});
