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/applyProductDetailEditInDrawer.ts
var applyProductDetailEditInDrawer_exports = {};
__export(applyProductDetailEditInDrawer_exports, {
  applyProductDetailEditInDrawer: () => applyProductDetailEditInDrawer,
  mergeNormalProductEditInDrawer: () => mergeNormalProductEditInDrawer
});
module.exports = __toCommonJS(applyProductDetailEditInDrawer_exports);
var import_utils = require("../../../components/booking/utils");
var import_utils2 = require("../../../components/booking/info/utils");
var import_utils3 = require("../../../components/booking/info2/service/addService/utils");
function applyProductDetailEditInDrawer(input) {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
  const { cacheItem: item, formValues, detailResult, showNumber = true } = input;
  const { e, detail } = detailResult;
  const _detail = detail || item;
  const other = JSON.parse(JSON.stringify(e || {}));
  other.session = e == null ? void 0 : e.session;
  const resolvedQuantity = showNumber ? (e == null ? void 0 : e.quantity) || (formValues == null ? void 0 : formValues.quantity) || ((_a = item._extend) == null ? void 0 : _a.quantity) || 1 : (formValues == null ? void 0 : formValues.quantity) ?? ((_b = item._extend) == null ? void 0 : _b.quantity) ?? (e == null ? void 0 : e.quantity) ?? 1;
  const nextItem = {
    ...item,
    ..._detail,
    product_id: item.id ?? item.product_id,
    _id: item == null ? void 0 : item._id,
    _key: (e == null ? void 0 : e.key) ?? item._key,
    _extend: {
      ...item._extend,
      ...formValues,
      quantity: resolvedQuantity,
      other,
      priceOverride: ((_c = _detail._extend) == null ? void 0 : _c.priceOverride) ?? ((_d = item._extend) == null ? void 0 : _d.priceOverride)
    },
    new: (item == null ? void 0 : item.new) ?? 0
  };
  const total = (0, import_utils.getProductTotalPrice)(nextItem);
  const hadManualOverride = ((_e = nextItem._extend) == null ? void 0 : _e.priceOverride) !== void 0 && ((_f = nextItem._extend) == null ? void 0 : _f.priceOverride) !== null && ((_g = nextItem._extend) == null ? void 0 : _g.priceOverride) !== "";
  const preservedOriginTotal = (_h = item._extend) == null ? void 0 : _h.origin_total;
  nextItem._extend.total = total;
  nextItem._extend.origin_total = hadManualOverride ? preservedOriginTotal ?? total : total;
  try {
    nextItem._extend.capacity = (0, import_utils3.setDefaultCapacitys)({
      capacitys: (_i = nextItem._data) == null ? void 0 : _i.capacitys,
      cacheItem: nextItem
    });
  } catch {
  }
  const formPatch = {
    total,
    origin_total: nextItem._extend.origin_total,
    capacity: (_j = nextItem._extend) == null ? void 0 : _j.capacity,
    quantity: resolvedQuantity
  };
  const sessionDetail = (0, import_utils2.editSessionProduct)(nextItem, e == null ? void 0 : e.session);
  if (sessionDetail) {
    formPatch.start_time = sessionDetail.start_time;
    formPatch.duration = sessionDetail.duration;
  }
  return { cacheItem: nextItem, formPatch };
}
function mergeNormalProductEditInDrawer(input) {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
  const { cacheItem: item, editedCacheItem, formValues } = input;
  const editedExtend = (editedCacheItem == null ? void 0 : editedCacheItem._extend) || {};
  const nextItem = {
    ...item,
    ...editedCacheItem,
    _id: item == null ? void 0 : item._id,
    _key: editedCacheItem._key ?? item._key,
    new: (item == null ? void 0 : item.new) ?? 0,
    _data: item._data ?? editedCacheItem._data,
    _extend: {
      ...item._extend,
      ...editedExtend,
      ...formValues,
      resource: formValues.resource ?? ((_a = item._extend) == null ? void 0 : _a.resource),
      start_time: formValues.start_time ?? editedExtend.start_time ?? ((_b = item._extend) == null ? void 0 : _b.start_time),
      start_date: formValues.start_date ?? editedExtend.start_date ?? ((_c = item._extend) == null ? void 0 : _c.start_date),
      end_date: formValues.end_date ?? editedExtend.end_date ?? ((_d = item._extend) == null ? void 0 : _d.end_date),
      duration: formValues.duration ?? editedExtend.duration ?? ((_e = item._extend) == null ? void 0 : _e.duration),
      holder_id: formValues.holder_id ?? ((_f = item._extend) == null ? void 0 : _f.holder_id),
      note: formValues.note ?? ((_g = item._extend) == null ? void 0 : _g.note),
      other: editedExtend.other ?? ((_h = item._extend) == null ? void 0 : _h.other),
      total: editedExtend.total,
      origin_total: editedExtend.origin_total,
      quantity: editedExtend.quantity ?? formValues.quantity ?? ((_i = item._extend) == null ? void 0 : _i.quantity)
    }
  };
  return {
    cacheItem: nextItem,
    formPatch: {
      total: nextItem._extend.total,
      origin_total: nextItem._extend.origin_total,
      quantity: nextItem._extend.quantity,
      capacity: nextItem._extend.capacity
    }
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  applyProductDetailEditInDrawer,
  mergeNormalProductEditInDrawer
});
