function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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 算法；
 * - 每个画布作为独立区域，仅一条细边框作分隔，无背景色/网格；
 * - 画布名显示在边框外的标题带；标题不拦截图元交互；
 * - 仅渲染 ItemLayer（阅读态），与单画布的 hover/click 行为一致；编辑层不渲染。
 */
import React from 'react';
import classNames from 'classnames';
import ItemLayer from "./ItemLayer";
import useEngineContext from "../../../hooks/useEngineContext";
import { getFloorMapCanvasDisplayName, getFloorMapDisplayLocale, getFloorMapLayoutText } from "../utils/floorMapCanvasDisplay";
import { mergeCanvasesForTabs } from "../utils/mergeCanvasesForTabs";
import { FLOOR_MAP_LAYOUT_CLASS_PREFIX as PREFIX } from "../floorMapLayoutConstants";
import "./FloorMapOverview.less";
var I18N_OVERVIEW_AREA_BADGE = 'pisell-floor-map-layout.overview.area-title-badge';
var I18N_EMPTY = 'pisell-floor-map-layout.overview.empty';
export function FloorMapOverview(props) {
  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,
    onSelectCanvas = props.onSelectCanvas,
    className = props.className;

  /** 显示语言优先引擎存储 umi_locale，getCurrentLocale 兜底；徽标与画布名统一用它 */
  var engineCtx = useEngineContext();
  var displayLocale = getFloorMapDisplayLocale(engineCtx);
  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%'
      }
    }, getFloorMapLayoutText(I18N_EMPTY, displayLocale));
  }

  /**
   * 用 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, displayLocale));
    }
  } 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-block"),
      style: {
        position: 'absolute',
        left: area.x,
        top: area.y,
        width: area.contentWidth
      }
    }, /*#__PURE__*/React.createElement("div", {
      className: "".concat(PREFIX, "-overview-area-title"),
      title: displayName,
      style: {
        height: area.titleBandHeight,
        transform: "scale(".concat(inverseScale, ")"),
        transformOrigin: 'top left',
        width: "".concat(100 * safeScale, "%"),
        maxWidth: "".concat(area.contentWidth * safeScale, "px")
      }
    }, onSelectCanvas ? /*#__PURE__*/React.createElement("button", {
      type: "button",
      className: classNames("".concat(PREFIX, "-overview-area-title-inner"), "".concat(PREFIX, "-overview-area-title-inner--clickable")),
      title: displayName,
      "aria-label": displayName,
      onClick: function onClick(e) {
        e.stopPropagation();
        onSelectCanvas(area.canvasId);
      }
    }, /*#__PURE__*/React.createElement("span", {
      className: "".concat(PREFIX, "-overview-area-title-badge")
    }, getFloorMapLayoutText(I18N_OVERVIEW_AREA_BADGE, displayLocale)), /*#__PURE__*/React.createElement("span", {
      className: "".concat(PREFIX, "-overview-area-title-text")
    }, displayName)) : /*#__PURE__*/React.createElement("span", {
      className: "".concat(PREFIX, "-overview-area-title-inner")
    }, /*#__PURE__*/React.createElement("span", {
      className: "".concat(PREFIX, "-overview-area-title-badge")
    }, getFloorMapLayoutText(I18N_OVERVIEW_AREA_BADGE, displayLocale)), /*#__PURE__*/React.createElement("span", {
      className: "".concat(PREFIX, "-overview-area-title-text")
    }, displayName))), /*#__PURE__*/React.createElement("div", {
      className: classNames("".concat(PREFIX, "-overview-area"), _defineProperty({}, "".concat(PREFIX, "-overview-area--clickable"), Boolean(onSelectCanvas))),
      style: {
        width: area.contentWidth,
        height: area.contentHeight
      },
      onClick: onSelectCanvas ? function (e) {
        /** 点到图元交给图元自身处理，仅空白区域才切换画布 */
        if (e.target.closest(".".concat(PREFIX, "-item"))) {
          return;
        }
        onSelectCanvas(area.canvasId);
      } : undefined
    }, /*#__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;