const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_mergeCanvasesForTabs = require("./mergeCanvasesForTabs.js");
const require_layoutMeasurements = require("./layoutMeasurements.js");
const require_floorMapConfigMerge = require("./floorMapConfigMerge.js");
const require_floorMapCanvasStage = require("./floorMapCanvasStage.js");
//#region src/components/pisellFloorMapLayout/utils/floorMapOverviewLayout.ts
/**
* 「All」全览视图布局：把所有启用画布按各自原始尺寸（同一比例尺）紧凑装箱，
* 产出整体宽高 + 每个画布区域在大画布坐标系下的位置与图元，供 PisellFloorMapLayout
* 在主 TransformWrapper 内复用渲染（共享 ViewControls / 视口锁定 / 全屏 / fitBounds）。
*
* 不依赖 React，仅数据计算，便于单测与缓存。
*/
/**
* 构造 All 视图布局。
*
* - 顺序：按 `canvas.order` 升序，与顶部 Tab 顺序一致；
* - 尺寸：每个画布按 {@link computeFloorMapContentStage}（含其自己的 boundingPadding）
*   推导内容尺寸，所有画布共享同一比例尺，不缩放；
* - 装箱：{@link packCanvasesIntoShelves} 行装填，目标行宽 ≈ √总面积。
*/
function buildFloorMapOverviewLayout(params) {
	const { config, globalMapLayer, cellSize, itemUnit, areaGap } = params;
	const stageList = require_mergeCanvasesForTabs.mergeCanvasesForTabs(config).filter((c) => c.enabled).sort((a, b) => a.order - b.order).map((canvas) => {
		var _effectiveMapLayer$bo;
		const items = require_floorMapConfigMerge.mergeCanvasItems(canvas.id, config, cellSize);
		const effectiveMapLayer = canvas.mapLayer ? require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, globalMapLayer !== null && globalMapLayer !== void 0 ? globalMapLayer : {}), canvas.mapLayer) : globalMapLayer;
		const boundingPadding = (_effectiveMapLayer$bo = effectiveMapLayer === null || effectiveMapLayer === void 0 ? void 0 : effectiveMapLayer.boundingPadding) !== null && _effectiveMapLayer$bo !== void 0 ? _effectiveMapLayer$bo : 56;
		const stage = require_floorMapCanvasStage.computeFloorMapContentStage({
			items,
			cellSize,
			itemGap: require_layoutMeasurements.gapToPx(effectiveMapLayer === null || effectiveMapLayer === void 0 ? void 0 : effectiveMapLayer.gap),
			itemUnit,
			boundingPadding,
			preferPixelBoundingBox: true
		});
		return {
			canvasId: canvas.id,
			items,
			contentWidth: stage.contentWidth,
			contentHeight: stage.contentHeight,
			contentOffsetX: stage.contentOffsetX,
			contentOffsetY: stage.contentOffsetY,
			cellSize
		};
	});
	const titleBandHeight = 36;
	const pack = require_floorMapCanvasStage.packCanvasesIntoShelves(stageList.map((s) => ({
		width: s.contentWidth,
		height: s.contentHeight + titleBandHeight
	})), areaGap);
	return {
		areas: stageList.map((s, i) => {
			var _pack$positions$i$x, _pack$positions$i, _pack$positions$i$y, _pack$positions$i2;
			return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, s), {}, {
				x: (_pack$positions$i$x = (_pack$positions$i = pack.positions[i]) === null || _pack$positions$i === void 0 ? void 0 : _pack$positions$i.x) !== null && _pack$positions$i$x !== void 0 ? _pack$positions$i$x : 0,
				y: (_pack$positions$i$y = (_pack$positions$i2 = pack.positions[i]) === null || _pack$positions$i2 === void 0 ? void 0 : _pack$positions$i2.y) !== null && _pack$positions$i$y !== void 0 ? _pack$positions$i$y : 0,
				titleBandHeight
			});
		}),
		totalWidth: pack.totalWidth,
		totalHeight: pack.totalHeight
	};
}
//#endregion
exports.buildFloorMapOverviewLayout = buildFloorMapOverviewLayout;
