const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_icon_es_AlertTriangle = require("@pisell/icon/es/AlertTriangle");
_pisell_icon_es_AlertTriangle = require_runtime.__toESM(_pisell_icon_es_AlertTriangle);
//#region src/plus/salesSdk/bookingEditService/normalizeResourceDisplay.tsx
/** 与 Info2 `booking/mock.ts#getNoResource2`、OS `noResource.ts` 约定：id=0 为「无资源」占位行。 */
function getNoResourceDisplayLabel() {
	return _pisell_utils.locales.getText("pisell1.text.no-resource") || "No resource";
}
/**
* 资源下拉选项 label（对齐 info2 `formatResources` 内 JSX）。
* 不可用（!usable）或未绑定（unbound）时展示红色三角标。
*/
function buildResourceOptionLabel(row) {
	var _row$id;
	const text = (row === null || row === void 0 ? void 0 : row.labelText) || (row === null || row === void 0 ? void 0 : row.main_field) || String((_row$id = row === null || row === void 0 ? void 0 : row.id) !== null && _row$id !== void 0 ? _row$id : "");
	if (!((row === null || row === void 0 ? void 0 : row.id) !== 0 && (!(row === null || row === void 0 ? void 0 : row.usable) || (row === null || row === void 0 ? void 0 : row.unbound)))) return text;
	return /* @__PURE__ */ react.default.createElement("div", { className: "resource-option" }, /* @__PURE__ */ react.default.createElement("div", { className: "like-wrap" }), /* @__PURE__ */ react.default.createElement("span", { className: "resource-option-label-text" }, text), /* @__PURE__ */ react.default.createElement(_pisell_icon_es_AlertTriangle.default, { className: "resource-option-alert-icon" }));
}
function patchResourceRow(row, noResourceLabel) {
	if ((row === null || row === void 0 ? void 0 : row.id) !== 0 && (row === null || row === void 0 ? void 0 : row.form_record_id) !== 0) {
		const next = require_objectSpread2._objectSpread2({}, row);
		if (!next.label) next.label = buildResourceOptionLabel(next);
		if (!next.labelText) next.labelText = next.main_field;
		return next;
	}
	const next = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, row), {}, {
		main_field: row.main_field || noResourceLabel,
		labelText: row.labelText || noResourceLabel,
		room_name: row.room_name || noResourceLabel
	});
	next.label = buildResourceOptionLabel(next);
	return next;
}
/**
* OS `getNoResource2` 的文案字段为空，Select 会回退显示 value `0`。
* 在 SalesSdk 抽屉内补齐与 Info2 mock 一致的展示文案，并补上不可用三角标 label。
*/
function normalizeResourceDisplayList(resources) {
	if (!Array.isArray(resources)) return [];
	const label = getNoResourceDisplayLabel();
	return resources.map((formItem) => {
		const renderList = (formItem.renderList || []).map((row) => patchResourceRow(row, label));
		let renderListMaps = formItem.renderListMaps;
		if (renderListMaps && typeof renderListMaps === "object") renderListMaps = Object.fromEntries(Object.entries(renderListMaps).map(([key, row]) => [key, patchResourceRow(row, label)]));
		return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, formItem), {}, {
			renderList,
			renderListMaps
		});
	});
}
function normalizeResourceDisplayMaps(maps) {
	if (!maps || typeof maps !== "object") return {};
	const label = getNoResourceDisplayLabel();
	const next = {};
	for (const formId of Object.keys(maps)) {
		const entry = maps[formId];
		if (!(entry === null || entry === void 0 ? void 0 : entry.renderListMaps)) {
			next[formId] = entry;
			continue;
		}
		const renderListMaps = Object.fromEntries(Object.entries(entry.renderListMaps).map(([key, row]) => [key, patchResourceRow(row, label)]));
		next[formId] = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, entry), {}, { renderListMaps });
	}
	return next;
}
//#endregion
exports.normalizeResourceDisplayList = normalizeResourceDisplayList;
exports.normalizeResourceDisplayMaps = normalizeResourceDisplayMaps;
