var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/salesSdk/bookingEditService/prepareCacheItemForBookingEdit.ts
var prepareCacheItemForBookingEdit_exports = {};
__export(prepareCacheItemForBookingEdit_exports, {
  prepareCacheItemForBookingEdit: () => prepareCacheItemForBookingEdit
});
module.exports = __toCommonJS(prepareCacheItemForBookingEdit_exports);
var import_utils = require("../../../components/booking/info2/service/addService/utils");
var import_utils2 = require("../../../components/booking/utils");
var import_normalizeResourceDisplay = require("./normalizeResourceDisplay");
var import_resolveCacheItemForResourceCheck = require("./resolveCacheItemForResourceCheck");
function prepareCacheItemForBookingEdit(cacheItem) {
  var _a, _b, _c, _d;
  if (!cacheItem) return cacheItem;
  const item = {
    ...cacheItem,
    _extend: { ...cacheItem._extend || {} },
    _data: cacheItem._data ? { ...cacheItem._data } : void 0
  };
  const ext = item._extend;
  if (ext.price == null) {
    ext.price = (0, import_utils2.getMainPrice)(item, item.price ?? item.selling_price);
  }
  const computedTotal = (0, import_utils2.getProductTotalPrice)(item);
  const hasTotal = ext.total !== void 0 && ext.total !== null && ext.total !== "";
  if (!hasTotal || Number(ext.total) === 0 && computedTotal > 0) {
    ext.total = computedTotal;
  }
  if (ext.origin_total == null || ext.origin_total === "") {
    ext.origin_total = ext.total ?? computedTotal;
  }
  if ((_b = (_a = item._data) == null ? void 0 : _a.resourcesOrigin) == null ? void 0 : _b.length) {
    try {
      const cacheForResources = (0, import_resolveCacheItemForResourceCheck.resolveCacheItemForResourceCheck)(item);
      const res = (0, import_utils.formatResources)({
        cacheItem: cacheForResources,
        resourcesOrigin: item._data.resourcesOrigin
      });
      if (res == null ? void 0 : res.list) {
        item._data.resources = (0, import_normalizeResourceDisplay.normalizeResourceDisplayList)(res.list);
        item._data.resourceMaps = (0, import_normalizeResourceDisplay.normalizeResourceDisplayMaps)(res.maps);
      }
    } catch (err) {
      console.warn("[SalesSdk] prepareCacheItemForBookingEdit formatResources 失败", err);
    }
  } else if ((_d = (_c = item._data) == null ? void 0 : _c.resources) == null ? void 0 : _d.length) {
    item._data.resources = (0, import_normalizeResourceDisplay.normalizeResourceDisplayList)(item._data.resources);
    item._data.resourceMaps = (0, import_normalizeResourceDisplay.normalizeResourceDisplayMaps)(item._data.resourceMaps);
  }
  return item;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  prepareCacheItemForBookingEdit
});
