var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pisellFloorMapLayout/components/FloorMapBuiltinShapeElement.tsx
var FloorMapBuiltinShapeElement_exports = {};
__export(FloorMapBuiltinShapeElement_exports, {
  FloorMapBuiltinShapeElement: () => FloorMapBuiltinShapeElement
});
module.exports = __toCommonJS(FloorMapBuiltinShapeElement_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_floorMapBuiltinShapes = require("../utils/floorMapBuiltinShapes");
var PREFIX = "pisell-floor-map-layout";
var I18N = "pisell-floor-map-layout.builtin-shape";
function FloorMapBuiltinShapeElement(props) {
  const { builtinShapeKey, name, fillColor, strokeColor } = props;
  const def = (0, import_floorMapBuiltinShapes.getFloorMapBuiltinShapeDef)(builtinShapeKey);
  const fallbackLabel = name != null && String(name).trim() ? String(name).trim() : import_utils.locales.getText(`${I18N}.default-name`);
  const orientationAware = !!(def == null ? void 0 : def.orientationAware);
  const wrapperRef = (0, import_react.useRef)(null);
  const [size, setSize] = (0, import_react.useState)(null);
  (0, import_react.useLayoutEffect)(() => {
    if (!orientationAware) return;
    const el = wrapperRef.current;
    if (!el) return;
    const measure = (w, h) => {
      setSize((prev) => prev && prev.w === w && prev.h === h ? prev : { w, h });
    };
    const rect = el.getBoundingClientRect();
    measure(rect.width, rect.height);
    const ro = new ResizeObserver((entries) => {
      const e = entries[0];
      if (!e) return;
      measure(e.contentRect.width, e.contentRect.height);
    });
    ro.observe(el);
    return () => ro.disconnect();
  }, [orientationAware]);
  if (!def) {
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: `${PREFIX}-builtin-shape-placeholder`,
        style: {
          width: "100%",
          height: "100%",
          boxSizing: "border-box",
          display: "flex",
          flexDirection: "column",
          alignItems: "center",
          justifyContent: "center",
          padding: 8,
          background: "#fafafa",
          border: "2px dashed #bfbfbf",
          borderRadius: 4,
          fontSize: 11,
          color: "#8c8c8c",
          textAlign: "center",
          lineHeight: 1.4,
          overflow: "hidden"
        }
      },
      /* @__PURE__ */ import_react.default.createElement("span", { style: { fontWeight: 600, color: "#595959", marginBottom: 4 } }, fallbackLabel),
      /* @__PURE__ */ import_react.default.createElement("span", null, import_utils.locales.getText(`${I18N}.hint-no-key`))
    );
  }
  const isVertical = orientationAware && size != null && size.h > size.w;
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      ref: wrapperRef,
      className: `${PREFIX}-builtin-shape`,
      style: {
        width: "100%",
        height: "100%",
        display: "block",
        position: "relative",
        pointerEvents: "none",
        userSelect: "none",
        overflow: "hidden"
      },
      "aria-label": fallbackLabel,
      role: "img",
      "data-orientation": isVertical ? "vertical" : "horizontal"
    },
    isVertical ? (
      /**
       * 容器更高时，让内层方框 swap dims（h × w），再 `rotate(90deg)`：
       * - 旋转前框尺寸 = 父容器 height × width；
       * - 旋转后视觉占位 = 父容器 width × height（刚好填满）；
       * - SVG 在内层用 100% 宽高，最终图形按原始横向 viewBox 比例缩放并旋转，
       *   保持沙发坐垫 / 大门门扇等细节比例不被压扁。
       */
      /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          style: {
            position: "absolute",
            left: "50%",
            top: "50%",
            width: size.h,
            height: size.w,
            transform: "translate(-50%, -50%) rotate(90deg)",
            transformOrigin: "center center"
          }
        },
        def.render({ fillColor, strokeColor })
      )
    ) : def.render({ fillColor, strokeColor })
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FloorMapBuiltinShapeElement
});
