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; }
/**
 * 从平面图 sceneElements 收集已绑定到指定数据源的 recordId，供画布专用 booking 的 form_record_ids。
 */

/** 无绑定图元时固定引用，避免 `extraRequestParams` 每次 render 新对象触发 booking 请求死循环 */
var EMPTY_BOUND_FORM_RECORD_IDS = [];
function parseRecordIdToPositiveInt(recordId) {
  var t = recordId.trim();
  if (!t || t === '0') return null;
  var n = Number(t);
  if (Number.isFinite(n) && n > 0) return Math.trunc(n);
  if (/^\d+$/.test(t)) return Math.trunc(Number(t));
  return null;
}

/**
 * @param sceneElements 当前平面图配置中的图元列表
 * @param gridDataSourceKey 与 RecordBoard / 图元 binding 一致的数据源 key（默认 tables）
 */
export function sceneElementsToBoundFormRecordIds(sceneElements, gridDataSourceKey) {
  if (!Array.isArray(sceneElements) || sceneElements.length === 0) {
    return EMPTY_BOUND_FORM_RECORD_IDS;
  }
  var seen = new Set();
  var out = [];
  var _iterator = _createForOfIteratorHelper(sceneElements),
    _step;
  try {
    for (_iterator.s(); !(_step = _iterator.n()).done;) {
      var _db$recordId;
      var el = _step.value;
      var db = el === null || el === void 0 ? void 0 : el.dataBinding;
      if (!db || db.dataSourceKey !== gridDataSourceKey) continue;
      var n = parseRecordIdToPositiveInt(String((_db$recordId = db.recordId) !== null && _db$recordId !== void 0 ? _db$recordId : ''));
      if (n != null && !seen.has(n)) {
        seen.add(n);
        out.push(n);
      }
    }
  } catch (err) {
    _iterator.e(err);
  } finally {
    _iterator.f();
  }
  return out;
}