const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
require("../types.js");
const require_floorMapBuiltinShapes = require("./floorMapBuiltinShapes.js");
//#region src/components/pisellFloorMapLayout/utils/floorMapToolbarPalette.ts
/** 解析侧栏每类展示上限（至少 1） */
function resolvePaletteSidebarVisibleLimit(limit) {
	return Math.max(1, Math.floor(limit !== null && limit !== void 0 ? limit : 5));
}
/** 分类下图元数是否应显示「查看全部」 */
function shouldShowPaletteViewAll(entryCount, limit) {
	return entryCount > resolvePaletteSidebarVisibleLimit(limit);
}
/** 侧栏直接展示的 palette 条目（前 N 项） */
function getPaletteSidebarVisibleEntries(entries, limit) {
	return entries.slice(0, resolvePaletteSidebarVisibleLimit(limit));
}
function buildToolbarPaletteEntries(kinds, resolveBuiltinLabel) {
	const out = [];
	for (const kind of kinds) {
		if (kind.value === "floorMapBuiltinShape") {
			for (const shapeDef of require_floorMapBuiltinShapes.FLOOR_MAP_BUILTIN_SHAPES) out.push({
				key: `builtin:${kind.value}:${shapeDef.key}`,
				kind,
				builtinShapeKey: shapeDef.key,
				shapeDef,
				label: resolveBuiltinLabel(shapeDef)
			});
			continue;
		}
		out.push({
			key: `kind:${kind.value}`,
			kind,
			label: kind.label
		});
	}
	return out;
}
/**
* 按弹窗内各条目数量展开为落点列表（数量为 n 则重复 n 次，落点时阶梯偏移）。
*/
function expandPaletteEntriesByQuantity(entries, quantities) {
	const out = [];
	for (const e of entries) {
		var _quantities$e$key;
		const n = Math.max(0, Math.floor((_quantities$e$key = quantities[e.key]) !== null && _quantities$e$key !== void 0 ? _quantities$e$key : 0));
		for (let i = 0; i < n; i += 1) out.push(require_objectSpread2._objectSpread2({ elementKind: e.kind.value }, e.builtinShapeKey ? { builtinShapeKey: e.builtinShapeKey } : {}));
	}
	return out;
}
//#endregion
exports.buildToolbarPaletteEntries = buildToolbarPaletteEntries;
exports.expandPaletteEntriesByQuantity = expandPaletteEntriesByQuantity;
exports.getPaletteSidebarVisibleEntries = getPaletteSidebarVisibleEntries;
exports.shouldShowPaletteViewAll = shouldShowPaletteViewAll;
