function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function (_e) { function e(_x) { return _e.apply(this, arguments); } e.toString = function () { return _e.toString(); }; return e; }(function (e) { throw e; }), f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function (_e2) { function e(_x2) { return _e2.apply(this, arguments); } e.toString = function () { return _e2.toString(); }; return e; }(function (e) { didErr = true; err = e; }), f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
/**
 * FloorMapOverview - 阅读态「All」全览视图（纯渲染版）
 *
 * 仅负责把 {@link OverviewLayout} 中各画布的图元渲染到对应的绝对定位区域里；
 * 由 PisellFloorMapLayout 在主 TransformWrapper 内挂载，与单画布共享同一套
 * 视口控件（缩放、平移、锁定、全屏、fitBounds、网格按钮等）。
 *
 * 设计要点：
 * - 不再自带 TransformWrapper / ResizeObserver / fit 算法；
 * - 每个画布作为独立区域，仅一条细边框作分隔，无背景色/网格；
 * - 区域左上角用小 chip 显示画布名；chip 不拦截图元交互；
 * - 仅渲染 ItemLayer（阅读态），与单画布的 hover/click 行为一致；编辑层不渲染。
 */
import React from 'react';
import classNames from 'classnames';
import { locales } from '@pisell/utils';
import ItemLayer from "./ItemLayer";
import useEngineContext from "../../../hooks/useEngineContext";
import { getFloorMapCanvasDisplayName } from "../utils/floorMapCanvasDisplay";
import { mergeCanvasesForTabs } from "../utils/mergeCanvasesForTabs";
import { FLOOR_MAP_LAYOUT_CLASS_PREFIX as PREFIX } from "../floorMapLayoutConstants";
import "./FloorMapOverview.less";
var I18N_EMPTY = 'pisell-floor-map-layout.overview.empty';
export function FloorMapOverview(props) {
  var _engineCtx$engine;
  var overviewLayout = props.overviewLayout,
    config = props.config,
    _props$itemUnit = props.itemUnit,
    itemUnit = _props$itemUnit === void 0 ? 'pixel' : _props$itemUnit,
    renderItem = props.renderItem,
    viewportScale = props.viewportScale,
    _props$enableHover = props.enableHover,
    enableHover = _props$enableHover === void 0 ? true : _props$enableHover,
    onItemClick = props.onItemClick,
    onItemHover = props.onItemHover,
    onItemLeave = props.onItemLeave,
    getMergedItemWrapperStyle = props.getMergedItemWrapperStyle,
    readModeSelectedItemId = props.readModeSelectedItemId,
    className = props.className;
  var engineCtx = useEngineContext();
  var engineLocale = (engineCtx === null || engineCtx === void 0 || (_engineCtx$engine = engineCtx.engine) === null || _engineCtx$engine === void 0 || (_engineCtx$engine = _engineCtx$engine.props) === null || _engineCtx$engine === void 0 ? void 0 : _engineCtx$engine.locale) || 'zh-CN';
  if (overviewLayout.areas.length === 0) {
    return /*#__PURE__*/React.createElement("div", {
      className: classNames("".concat(PREFIX, "-overview"), "".concat(PREFIX, "-overview--empty"), className),
      style: {
        width: '100%',
        height: '100%'
      }
    }, locales.getText(I18N_EMPTY));
  }

  /**
   * 用 mergeCanvasesForTabs 构造 canvasId → displayName 的映射；
   * 避免在循环里多次调用。
   */
  var displayNameById = new Map();
  var _iterator = _createForOfIteratorHelper(mergeCanvasesForTabs(config)),
    _step;
  try {
    for (_iterator.s(); !(_step = _iterator.n()).done;) {
      var canvas = _step.value;
      displayNameById.set(canvas.id, getFloorMapCanvasDisplayName(canvas, engineLocale));
    }
  } catch (err) {
    _iterator.e(err);
  } finally {
    _iterator.f();
  }
  return /*#__PURE__*/React.createElement("div", {
    className: classNames("".concat(PREFIX, "-overview"), className),
    style: {
      position: 'relative',
      width: overviewLayout.totalWidth,
      height: overviewLayout.totalHeight
    }
  }, overviewLayout.areas.map(function (area) {
    var _displayNameById$get;
    var displayName = (_displayNameById$get = displayNameById.get(area.canvasId)) !== null && _displayNameById$get !== void 0 ? _displayNameById$get : area.canvasId;
    var safeScale = viewportScale != null && Number.isFinite(viewportScale) && viewportScale > 0 ? viewportScale : 1;
    var inverseScale = 1 / safeScale;
    return /*#__PURE__*/React.createElement("div", {
      key: area.canvasId,
      className: "".concat(PREFIX, "-overview-area"),
      style: {
        position: 'absolute',
        left: area.x,
        top: area.y,
        width: area.contentWidth,
        height: area.contentHeight
      }
    }, /*#__PURE__*/React.createElement("span", {
      className: "".concat(PREFIX, "-overview-area-title"),
      title: displayName,
      style: {
        transform: "scale(".concat(inverseScale, ")"),
        transformOrigin: 'top left',
        maxWidth: "calc((100% - 16px) * ".concat(safeScale, ")")
      }
    }, displayName), /*#__PURE__*/React.createElement(ItemLayer, {
      items: area.items,
      renderItem: renderItem,
      viewportScale: viewportScale,
      cellSize: area.cellSize,
      itemUnit: itemUnit,
      contentWidth: area.contentWidth,
      contentHeight: area.contentHeight,
      contentOffsetX: area.contentOffsetX,
      contentOffsetY: area.contentOffsetY,
      enableHover: enableHover,
      itemHoverOutline: enableHover,
      onItemClick: onItemClick,
      onItemHover: onItemHover,
      onItemLeave: onItemLeave,
      getMergedItemWrapperStyle: getMergedItemWrapperStyle,
      readModeSelectedItemId: readModeSelectedItemId
    }));
  }));
}
export default FloorMapOverview;