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/floorMapConfigMerge.ts
var floorMapConfigMerge_exports = {};
__export(floorMapConfigMerge_exports, {
  mergeCanvasItems: () => mergeCanvasItems
});
module.exports = __toCommonJS(floorMapConfigMerge_exports);
var import_types = require("../types");
var import_floorMapElementKindUtils = require("./floorMapElementKindUtils");
var import_floorMapBuiltinShapes = require("./floorMapBuiltinShapes");
var DEFAULT_SIZE = 48;
var IMAGE_KIND_DEFAULT_SIZE = { width: 400, height: 240 };
var BUILTIN_SHAPE_FALLBACK_SIZE = { width: 96, height: 96 };
var ZONE_KIND_DEFAULT_SIZE = { width: 240, height: 160 };
var ZONE_DEFAULT_Z_INDEX = -100;
function getDefaultSize(elementKind, elementKinds, element) {
  if (!elementKind) return { width: DEFAULT_SIZE, height: DEFAULT_SIZE };
  if (elementKind === import_types.FLOOR_MAP_IMAGE_ELEMENT_KIND) {
    return { ...IMAGE_KIND_DEFAULT_SIZE };
  }
  if (elementKind === import_types.FLOOR_MAP_BUILTIN_SHAPE_ELEMENT_KIND) {
    const def = (0, import_floorMapBuiltinShapes.getFloorMapBuiltinShapeDef)(element == null ? void 0 : element.builtinShapeKey);
    return def ? { ...def.defaultSize } : { ...BUILTIN_SHAPE_FALLBACK_SIZE };
  }
  if (elementKind === import_types.FLOOR_MAP_ZONE_ELEMENT_KIND) {
    return { ...ZONE_KIND_DEFAULT_SIZE };
  }
  const found = elementKinds.find((k) => k.value === elementKind);
  if (!found) return { width: DEFAULT_SIZE, height: DEFAULT_SIZE };
  return { width: DEFAULT_SIZE, height: DEFAULT_SIZE };
}
function mergeCanvasItems(canvasId, config, defaultCellSize = DEFAULT_SIZE) {
  const { sceneElements = [], elementKinds = [] } = config;
  const items = [];
  const onCanvas = sceneElements.filter((el) => el.canvasId === canvasId);
  for (const el of onCanvas) {
    const size = getDefaultSize(el.elementKind, elementKinds, el);
    const w = el.width ?? size.width ?? defaultCellSize;
    const h = el.height ?? size.height ?? defaultCellSize;
    const kindConfig = (0, import_floorMapElementKindUtils.getElementKindConfig)({ elementKinds }, el.elementKind);
    const isZone = Boolean(el.isZone) || el.elementKind === import_types.FLOOR_MAP_ZONE_ELEMENT_KIND;
    items.push({
      id: el.instanceId,
      instanceId: el.instanceId,
      x: el.x,
      y: el.y,
      width: w,
      height: h,
      name: el.name,
      zIndex: isZone && el.zIndex == null ? ZONE_DEFAULT_Z_INDEX : el.zIndex,
      shape: el.shape ?? (kindConfig == null ? void 0 : kindConfig.defaultShape),
      elementKind: el.elementKind,
      isZone,
      parentId: el.parentId ?? null,
      _sceneElement: el
    });
  }
  return items;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  mergeCanvasItems
});
