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/utils/appendPromotionTags.ts
var appendPromotionTags_exports = {};
__export(appendPromotionTags_exports, {
  appendPromotionTagsForProducts: () => appendPromotionTagsForProducts
});
module.exports = __toCommonJS(appendPromotionTags_exports);
var import_resolveLocalizedText = require("./resolveLocalizedText");
function appendPromotionTagsForProducts(products, evaluator) {
  if (!Array.isArray(products) || products.length === 0 || !evaluator) {
    return products || [];
  }
  const evaluatorInput = products.map((item, index) => ({
    id: index,
    product_id: Number((item == null ? void 0 : item.id) ?? (item == null ? void 0 : item.product_id) ?? 0) || 0,
    product_variant_id: Number((item == null ? void 0 : item.product_variant_id) ?? 0) || 0,
    name: (item == null ? void 0 : item.title) || (item == null ? void 0 : item.name) || "",
    price: Number((item == null ? void 0 : item.price) ?? 0) || 0,
    quantity: Number((item == null ? void 0 : item.quantity) ?? 1) || 1,
    bundle: []
  }));
  let strategies;
  try {
    strategies = evaluator.getProductsApplicableStrategies(
      { products: evaluatorInput },
      false
    );
  } catch (error) {
    console.warn("[SalesSdk] appendPromotionTagsForProducts: evaluator 调用失败", error);
    return products;
  }
  return products.map((item, index) => {
    const data = strategies[index];
    const tags = [];
    if (data == null ? void 0 : data.hasApplicableStrategy) {
      for (const strategy of data.applicableStrategies) {
        if (strategy.display) {
          tags.push({
            text: (0, import_resolveLocalizedText.resolveLocalizedText)(strategy.display.text),
            type: strategy.display.type,
            strategyId: strategy.strategyId
          });
        }
      }
    }
    if (tags.length === 0) {
      const { _promotionTags, ...rest } = item;
      return rest;
    }
    return { ...item, _promotionTags: tags };
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  appendPromotionTagsForProducts
});
