const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_utils = require("../../../components/booking/info2/service/addService/utils.js");
const require_utils$1 = require("../../../components/booking/utils.js");
const require_resolveCacheItemForResourceCheck = require("./resolveCacheItemForResourceCheck.js");
const require_normalizeResourceDisplay = require("./normalizeResourceDisplay.js");
//#region src/plus/salesSdk/bookingEditService/prepareCacheItemForBookingEdit.ts
/**
* 打开资源编辑抽屉前补齐 cacheItem 展示字段（对齐 Info2 addService callback）。
*
* - 价格：`total` / `origin_total`（OS getProductExtend 不写这两项）
* - 资源：用 Info2 formatResources 刷新 `_data.resources`，再 normalize 补齐 label / 不可用三角标
*/
function prepareCacheItemForBookingEdit(cacheItem) {
	var _item$_data, _item$_data2;
	if (!cacheItem) return cacheItem;
	const item = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, cacheItem), {}, {
		_extend: require_objectSpread2._objectSpread2({}, cacheItem._extend || {}),
		_data: cacheItem._data ? require_objectSpread2._objectSpread2({}, cacheItem._data) : void 0
	});
	const ext = item._extend;
	if (ext.price == null) {
		var _item$price;
		ext.price = require_utils$1.getMainPrice(item, (_item$price = item.price) !== null && _item$price !== void 0 ? _item$price : item.selling_price);
	}
	const computedTotal = require_utils$1.getProductTotalPrice(item);
	if (!(ext.total !== void 0 && ext.total !== null && ext.total !== "") || Number(ext.total) === 0 && computedTotal > 0) ext.total = computedTotal;
	if (ext.origin_total == null || ext.origin_total === "") {
		var _ext$total;
		ext.origin_total = (_ext$total = ext.total) !== null && _ext$total !== void 0 ? _ext$total : computedTotal;
	}
	if ((_item$_data = item._data) === null || _item$_data === void 0 || (_item$_data = _item$_data.resourcesOrigin) === null || _item$_data === void 0 ? void 0 : _item$_data.length) try {
		const res = require_utils.formatResources({
			cacheItem: require_resolveCacheItemForResourceCheck.resolveCacheItemForResourceCheck(item),
			resourcesOrigin: item._data.resourcesOrigin
		});
		if (res === null || res === void 0 ? void 0 : res.list) {
			item._data.resources = require_normalizeResourceDisplay.normalizeResourceDisplayList(res.list);
			item._data.resourceMaps = require_normalizeResourceDisplay.normalizeResourceDisplayMaps(res.maps);
		}
	} catch (err) {
		console.warn("[SalesSdk] prepareCacheItemForBookingEdit formatResources 失败", err);
	}
	else if ((_item$_data2 = item._data) === null || _item$_data2 === void 0 || (_item$_data2 = _item$_data2.resources) === null || _item$_data2 === void 0 ? void 0 : _item$_data2.length) {
		item._data.resources = require_normalizeResourceDisplay.normalizeResourceDisplayList(item._data.resources);
		item._data.resourceMaps = require_normalizeResourceDisplay.normalizeResourceDisplayMaps(item._data.resourceMaps);
	}
	return item;
}
//#endregion
exports.prepareCacheItemForBookingEdit = prepareCacheItemForBookingEdit;
