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/floorMapToolbarPalette.ts
var floorMapToolbarPalette_exports = {};
__export(floorMapToolbarPalette_exports, {
  FLOOR_MAP_TOOLBAR_PALETTE_VISIBLE_LIMIT: () => FLOOR_MAP_TOOLBAR_PALETTE_VISIBLE_LIMIT,
  buildToolbarPaletteEntries: () => buildToolbarPaletteEntries,
  expandPaletteEntriesByQuantity: () => expandPaletteEntriesByQuantity,
  getPaletteSidebarVisibleEntries: () => getPaletteSidebarVisibleEntries,
  isDirectPlacePaletteEntry: () => isDirectPlacePaletteEntry,
  paletteEntriesToBulkPlaceItems: () => paletteEntriesToBulkPlaceItems,
  resolvePaletteSidebarVisibleLimit: () => resolvePaletteSidebarVisibleLimit,
  shouldShowPaletteViewAll: () => shouldShowPaletteViewAll
});
module.exports = __toCommonJS(floorMapToolbarPalette_exports);
var import_types = require("../types");
var import_floorMapElementKindUtils = require("./floorMapElementKindUtils");
var import_floorMapBuiltinShapes = require("./floorMapBuiltinShapes");
var import_floorMapLayoutConstants = require("../floorMapLayoutConstants");
var FLOOR_MAP_TOOLBAR_PALETTE_VISIBLE_LIMIT = import_floorMapLayoutConstants.FLOOR_MAP_TOOLBAR_PALETTE_SIDEBAR_LIMIT;
function resolvePaletteSidebarVisibleLimit(limit) {
  const n = limit ?? import_floorMapLayoutConstants.FLOOR_MAP_TOOLBAR_PALETTE_SIDEBAR_LIMIT;
  return Math.max(1, Math.floor(n));
}
function shouldShowPaletteViewAll(entryCount, limit) {
  return entryCount > resolvePaletteSidebarVisibleLimit(limit);
}
function getPaletteSidebarVisibleEntries(entries, limit) {
  return entries.slice(0, resolvePaletteSidebarVisibleLimit(limit));
}
function isDirectPlacePaletteEntry(entry) {
  if (entry.builtinShapeKey) return true;
  return (0, import_floorMapElementKindUtils.isDirectPlacePaletteKind)(entry.kind);
}
function buildToolbarPaletteEntries(kinds, resolveBuiltinLabel) {
  const out = [];
  for (const kind of kinds) {
    if (kind.value === import_types.FLOOR_MAP_BUILTIN_SHAPE_ELEMENT_KIND) {
      for (const shapeDef of import_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;
}
function paletteEntriesToBulkPlaceItems(entries) {
  return expandPaletteEntriesByQuantity(
    entries,
    Object.fromEntries(entries.map((e) => [e.key, 1]))
  );
}
function expandPaletteEntriesByQuantity(entries, quantities) {
  const out = [];
  for (const e of entries) {
    const n = Math.max(0, Math.floor(quantities[e.key] ?? 0));
    for (let i = 0; i < n; i += 1) {
      out.push({
        elementKind: e.kind.value,
        ...e.builtinShapeKey ? { builtinShapeKey: e.builtinShapeKey } : {}
      });
    }
  }
  return out;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FLOOR_MAP_TOOLBAR_PALETTE_VISIBLE_LIMIT,
  buildToolbarPaletteEntries,
  expandPaletteEntriesByQuantity,
  getPaletteSidebarVisibleEntries,
  isDirectPlacePaletteEntry,
  paletteEntriesToBulkPlaceItems,
  resolvePaletteSidebarVisibleLimit,
  shouldShowPaletteViewAll
});
