const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
//#region src/plus/salesSdk/utils/syncBundleFromExtendOther.ts
/**
* 将 cacheItem._extend.other.bundle 中的折后单价同步到订单行 product_bundle。
* 手动改价后 origin 快照已正确，但 product_bundle 可能未随 updates 写入。
*/
function syncBundleFromExtendOther(productBundle, otherBundle) {
	if (!Array.isArray(otherBundle) || otherBundle.length === 0) return productBundle;
	const priceById = /* @__PURE__ */ new Map();
	otherBundle.forEach((item) => {
		var _item$price;
		if ((item === null || item === void 0 ? void 0 : item.id) == null) return;
		const unit = (_item$price = item.price) !== null && _item$price !== void 0 ? _item$price : item.bundle_selling_price;
		if (unit === void 0 || unit === null) return;
		priceById.set(String(item.id), String(unit));
	});
	return (Array.isArray(productBundle) && productBundle.length > 0 ? productBundle : otherBundle).map((item) => {
		const unit = priceById.get(String(item === null || item === void 0 ? void 0 : item.id));
		if (unit === void 0) return item;
		return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, {
			price: unit,
			bundle_selling_price: unit
		});
	});
}
//#endregion
exports.syncBundleFromExtendOther = syncBundleFromExtendOther;
