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/giftSelect/giftSkuPrefill.ts
var giftSkuPrefill_exports = {};
__export(giftSkuPrefill_exports, {
  buildGiftSkuInitValue: () => buildGiftSkuInitValue,
  enrichDetailPayloadWithInitValue: () => enrichDetailPayloadWithInitValue,
  hasExistingGiftSkuSelection: () => hasExistingGiftSkuSelection
});
module.exports = __toCommonJS(giftSkuPrefill_exports);
function hasExistingGiftSkuSelection(product) {
  if (!product) return false;
  const initValue = product.initValue;
  if (initValue && typeof initValue === "object") {
    if (Array.isArray(initValue.bundle) && initValue.bundle.length > 0) return true;
    if (Array.isArray(initValue.option) && initValue.option.length > 0) return true;
    if (Number(initValue.product_variant_id) > 0) return true;
  }
  const extend = product._extend;
  const sku = (extend == null ? void 0 : extend._skuValue) ?? (extend == null ? void 0 : extend.skuValue) ?? (extend == null ? void 0 : extend.other);
  if (!sku || typeof sku !== "object") return false;
  if (Array.isArray(sku.bundle) && sku.bundle.length > 0) return true;
  if (Array.isArray(sku.option) && sku.option.length > 0) return true;
  if (Number(sku.product_variant_id) > 0) return true;
  return false;
}
function buildGiftSkuInitValue(product) {
  if (!product) return null;
  if (product.initValue && typeof product.initValue === "object") {
    return product.initValue;
  }
  const extend = product._extend;
  const other = (extend == null ? void 0 : extend.other) ?? (extend == null ? void 0 : extend._skuValue) ?? (extend == null ? void 0 : extend.skuValue);
  if (!other || typeof other !== "object") return null;
  return {
    ...other,
    quantity: (extend == null ? void 0 : extend.quantity) ?? product.num ?? other.quantity ?? 1
  };
}
function enrichDetailPayloadWithInitValue(payload, product) {
  var _a;
  const initValue = buildGiftSkuInitValue(product);
  if (!initValue) return payload;
  const baseProduct = payload.productData ?? payload.item ?? {};
  return {
    ...payload,
    item: {
      ...payload.item ?? baseProduct,
      initValue: {
        ...((_a = payload.item) == null ? void 0 : _a.initValue) || {},
        ...initValue
      }
    },
    productData: {
      ...baseProduct,
      initValue: {
        ...baseProduct.initValue || {},
        ...initValue
      }
    }
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildGiftSkuInitValue,
  enrichDetailPayloadWithInitValue,
  hasExistingGiftSkuSelection
});
