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/shopFloorPlan/shopFloorPlanMapping.ts
var shopFloorPlanMapping_exports = {};
__export(shopFloorPlanMapping_exports, {
  sceneElementsToShopLayout: () => sceneElementsToShopLayout,
  shopLayoutToSceneElements: () => shopLayoutToSceneElements
});
module.exports = __toCommonJS(shopFloorPlanMapping_exports);
function parseResourceId(recordId) {
  if (recordId == null || recordId === "") return null;
  const n = Number(recordId);
  return Number.isFinite(n) && n > 0 ? Math.trunc(n) : null;
}
function isCircleShape(el) {
  return el.shape === "circle";
}
function sceneElementsToShopLayout(sceneElements) {
  return sceneElements.map((el) => {
    var _a, _b, _c, _d;
    const w = el.width ?? 100;
    const h = el.height ?? 100;
    const circle = isCircleShape(el);
    const rotation = typeof ((_a = el.extensions) == null ? void 0 : _a.rotation) === "number" ? el.extensions.rotation : Number((_b = el.extensions) == null ? void 0 : _b.rotation) || 0;
    const base = {
      id: el.instanceId,
      type: circle ? "circle" : "rect",
      label: ((_c = el.name) == null ? void 0 : _c.trim()) || "",
      x: el.x,
      y: el.y,
      rotation,
      color: el.fillColor ?? "#1a2332",
      border_color: el.strokeColor ?? "#ffffff",
      resource_id: parseResourceId((_d = el.dataBinding) == null ? void 0 : _d.recordId)
    };
    if (circle) {
      base.radius = Math.max(1, Math.round(Math.min(w, h) / 2));
    } else {
      base.width = w;
      base.height = h;
    }
    return base;
  });
}
function shopLayoutToSceneElements(layout, options) {
  const { canvasId, dataSourceKey, rectElementKind, circleElementKind } = options;
  return layout.map((item) => {
    var _a;
    const circle = item.type === "circle";
    const r = Math.max(1, Math.round(item.radius ?? 40));
    const w = circle ? r * 2 : item.width ?? 100;
    const h = circle ? r * 2 : item.height ?? 100;
    const rotation = typeof item.rotation === "number" ? item.rotation : 0;
    const el = {
      instanceId: String(item.id),
      canvasId,
      x: item.x,
      y: item.y,
      width: w,
      height: h,
      name: ((_a = item.label) == null ? void 0 : _a.trim()) || void 0,
      zIndex: 0,
      elementKind: circle ? circleElementKind : rectElementKind,
      shape: circle ? "circle" : void 0,
      fillColor: item.color,
      strokeColor: item.border_color,
      extensions: rotation !== 0 ? { rotation } : void 0
    };
    if (item.resource_id != null && Number.isFinite(Number(item.resource_id))) {
      el.dataBinding = {
        dataSourceKey,
        recordId: String(Math.trunc(Number(item.resource_id)))
      };
    }
    return el;
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  sceneElementsToShopLayout,
  shopLayoutToSceneElements
});
