//#region src/plus/pisellReservation/floorMap/floorMapBoundRecordIds.ts
/** 无绑定图元时固定引用，避免 `extraRequestParams` 每次 render 新对象触发 booking 请求死循环 */
const EMPTY_BOUND_FORM_RECORD_IDS = [];
/** 与 {@link EMPTY_BOUND_FORM_RECORD_IDS} 同理：稳定空数组引用 */
const EMPTY_BOUND_RECORD_ID_STRINGS = [];
function parseRecordIdToPositiveInt(recordId) {
	const t = recordId.trim();
	if (!t || t === "0") return null;
	const n = Number(t);
	if (Number.isFinite(n) && n > 0) return Math.trunc(n);
	if (/^\d+$/.test(t)) return Math.trunc(Number(t));
	return null;
}
/** 图元绑定是否属于当前网格数据源（旧布局常漏写 dataSourceKey，须与平面图一致放宽） */
function bindingDataSourceMatchesGrid(dataSourceKey, gridDataSourceKey) {
	const k = String(dataSourceKey !== null && dataSourceKey !== void 0 ? dataSourceKey : "").trim();
	if (!k) return true;
	return k === gridDataSourceKey;
}
/**
* @param sceneElements 当前平面图配置中的图元列表
* @param gridDataSourceKey 与 RecordBoard / 图元 binding 一致的数据源 key（默认 tables）
*/
function sceneElementsToBoundFormRecordIds(sceneElements, gridDataSourceKey) {
	if (!Array.isArray(sceneElements) || sceneElements.length === 0) return EMPTY_BOUND_FORM_RECORD_IDS;
	const seen = /* @__PURE__ */ new Set();
	const out = [];
	for (const el of sceneElements) {
		var _db$recordId;
		const db = el === null || el === void 0 ? void 0 : el.dataBinding;
		if (!db || !bindingDataSourceMatchesGrid(db.dataSourceKey, gridDataSourceKey)) continue;
		const 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);
		}
	}
	return out;
}
/**
* 画布图元绑定到指定数据源的 `recordId` 字符串列表（保序去重），供日历与预约条 `relation_id` 对齐。
* 与 {@link sceneElementsToBoundFormRecordIds} 不同：不要求可解析为正整数，避免低代码/远程布局里
* 合法 string id 被整段丢弃导致日历 `canvasResourceIdSet` 为空、三条视图都无列无条。
*/
function sceneElementsToBoundRecordIdStrings(sceneElements, gridDataSourceKey) {
	if (!Array.isArray(sceneElements) || sceneElements.length === 0) return EMPTY_BOUND_RECORD_ID_STRINGS;
	const seen = /* @__PURE__ */ new Set();
	const out = [];
	for (const el of sceneElements) {
		var _db$recordId2;
		const db = el === null || el === void 0 ? void 0 : el.dataBinding;
		if (!db || !bindingDataSourceMatchesGrid(db.dataSourceKey, gridDataSourceKey)) continue;
		const raw = String((_db$recordId2 = db.recordId) !== null && _db$recordId2 !== void 0 ? _db$recordId2 : "").trim();
		if (!raw || raw === "0") continue;
		if (!seen.has(raw)) {
			seen.add(raw);
			out.push(raw);
		}
	}
	return out;
}
//#endregion
exports.sceneElementsToBoundFormRecordIds = sceneElementsToBoundFormRecordIds;
exports.sceneElementsToBoundRecordIdStrings = sceneElementsToBoundRecordIdStrings;
