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(_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 e(_e2) { didErr = true; err = _e2; }, 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; }
import React from 'react';
import { FloorMapSelectionZoneElement, FLOOR_MAP_SELECTION_ZONE_ELEMENT_KIND } from '@pisell/materials';
import { TopologyDeviceCard } from "./TopologyDeviceCard";
import { TOPOLOGY_KIND_ICONS } from "./icons/TopologyIcons";
import { getTopologyElementKinds } from "./topologyElementKinds";

/** 按拓扑 kind 生成 FloorMap renderItemByKind 映射 */
export function getTopologyRenderItemByKind(devicesById) {
  var kinds = new Set(getTopologyElementKinds().map(function (k) {
    return k.value;
  }));
  var map = {};
  map[FLOOR_MAP_SELECTION_ZONE_ELEMENT_KIND] = function (item) {
    var _item$name, _item$_sceneElement;
    return /*#__PURE__*/React.createElement(FloorMapSelectionZoneElement, {
      name: (_item$name = item.name) !== null && _item$name !== void 0 ? _item$name : (_item$_sceneElement = item._sceneElement) === null || _item$_sceneElement === void 0 ? void 0 : _item$_sceneElement.name
    });
  };
  var _iterator = _createForOfIteratorHelper(kinds),
    _step;
  try {
    for (_iterator.s(); !(_step = _iterator.n()).done;) {
      var kind = _step.value;
      if (kind === FLOOR_MAP_SELECTION_ZONE_ELEMENT_KIND) continue;
      if (!TOPOLOGY_KIND_ICONS[kind]) continue;
      map[kind] = function (item) {
        var _item$_sceneElement2;
        var binding = (_item$_sceneElement2 = item._sceneElement) === null || _item$_sceneElement2 === void 0 ? void 0 : _item$_sceneElement2.dataBinding;
        var device = (binding === null || binding === void 0 ? void 0 : binding.recordId) != null ? devicesById.get(String(binding.recordId)) : undefined;
        return /*#__PURE__*/React.createElement(TopologyDeviceCard, {
          item: item,
          device: device
        });
      };
    }
  } catch (err) {
    _iterator.e(err);
  } finally {
    _iterator.f();
  }
  return map;
}