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/normalProductDetail/transformNormalProductConfirm.ts
var transformNormalProductConfirm_exports = {};
__export(transformNormalProductConfirm_exports, {
  prepareNormalProductEditCacheItem: () => prepareNormalProductEditCacheItem,
  transformNormalProductCreateConfirm: () => transformNormalProductCreateConfirm
});
module.exports = __toCommonJS(transformNormalProductConfirm_exports);
var import_lodash = require("lodash");
var import_utils = require("../../../components/booking/utils");
var import_utils2 = require("../../../components/booking/info2/service/editService/utils");
var import_utils3 = require("../../../components/ticketBooking/components/addServiceVariant/utils");
function syncSkuValueFromOther(data) {
  var _a;
  const other = (_a = data == null ? void 0 : data._extend) == null ? void 0 : _a.other;
  if (!other || !(data == null ? void 0 : data._extend)) return data;
  const snapshot = {
    product_id: other.product_id ?? data.product_id ?? data.id,
    product_variant_id: other.product_variant_id ?? 0,
    product_option_string: other.product_option_string ?? "",
    bundle: (0, import_lodash.cloneDeep)(other.bundle || []),
    option: (0, import_lodash.cloneDeep)(other.option || [])
  };
  data._extend.skuValue = snapshot;
  data._extend._skuValue = (0, import_lodash.cloneDeep)(snapshot);
  return data;
}
function resolveOriginTotalForSetPrice(extend, lineTotal) {
  const hasOverride = (extend == null ? void 0 : extend.priceOverride) !== void 0 && (extend == null ? void 0 : extend.priceOverride) !== null;
  const origin = Number(extend == null ? void 0 : extend.origin_total);
  if (Number.isFinite(origin) && origin > 0) {
    return origin;
  }
  if (hasOverride) {
    return lineTotal;
  }
  return lineTotal;
}
function transformNormalProductCreateConfirm(productId, data) {
  var _a, _b, _c, _d, _e, _f;
  const quantity = Number(((_a = data == null ? void 0 : data._extend) == null ? void 0 : _a.quantity) || 1);
  const basePrice = Number(((_b = data == null ? void 0 : data._extend) == null ? void 0 : _b.price) ?? (data == null ? void 0 : data.price) ?? 0) || 0;
  let detail = {
    ...data || {},
    id: productId,
    product_id: productId,
    _extend: {
      ...(data == null ? void 0 : data._extend) || {},
      price: ((_c = data == null ? void 0 : data._extend) == null ? void 0 : _c.price) ?? basePrice,
      origin_total: ((_d = data == null ? void 0 : data._extend) == null ? void 0 : _d.origin_total) ?? ((_e = data == null ? void 0 : data._extend) == null ? void 0 : _e.total) ?? basePrice,
      quantity,
      skuValue: (0, import_lodash.cloneDeep)(((_f = data == null ? void 0 : data._extend) == null ? void 0 : _f.skuValue) || {})
    }
  };
  const lineTotal = (0, import_utils.getProductTotalPrice)(detail);
  detail._extend.total = lineTotal;
  detail = (0, import_utils2.setProductPrice)(detail, {
    newTotal: lineTotal,
    origin_total: detail._extend.origin_total
  });
  let e = {
    product_id: productId,
    ...detail._extend.other,
    quantity
  };
  e = (0, import_utils3.formatDataKey)(e);
  return {
    e,
    extension_type: void 0,
    detail
  };
}
function prepareNormalProductEditCacheItem(data) {
  var _a, _b, _c;
  const extend = {
    price: (data == null ? void 0 : data.price) ?? 0,
    ...(data == null ? void 0 : data._extend) || {}
  };
  const normalized = {
    ...data || {},
    _extend: extend
  };
  const lineTotal = (0, import_utils.getProductTotalPrice)(normalized);
  normalized._extend = {
    ...extend,
    total: lineTotal,
    origin_total: resolveOriginTotalForSetPrice(extend, lineTotal)
  };
  if ((normalized == null ? void 0 : normalized.is_bundle) || (((_b = (_a = extend == null ? void 0 : extend.other) == null ? void 0 : _a.bundle) == null ? void 0 : _b.length) ?? 0) > 0) {
    normalized._extend.bundle_edit = 1;
  }
  const prepared = (0, import_utils2.setProductPrice)(normalized, {
    newTotal: lineTotal,
    origin_total: normalized._extend.origin_total
  });
  syncSkuValueFromOther(prepared);
  prepared.note = (_c = prepared._extend) == null ? void 0 : _c.note;
  return prepared;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  prepareNormalProductEditCacheItem,
  transformNormalProductCreateConfirm
});
