import { formatAmount } from '@pisell/utils';
import { getServiceTime } from "./formatTime";
var formatProductMessage = function formatProductMessage(product, utils) {
  var product_option_string = product.product_option_string,
    options = product.options,
    bundle = product.bundle,
    currency_symbol = product.currency_symbol,
    start_date = product.start_date,
    end_date = product.end_date,
    holder_id = product.holder_id,
    holders = product.holders,
    multiResources = product.multiResources;
  var str = '';
  if (start_date && end_date) {
    str += "".concat(getServiceTime(product, start_date, utils), " \n");
  }
  if (holder_id && Array.isArray(holders)) {
    var targetHolder = holders.find(function (holder) {
      return holder.id === holder_id;
    });
    if (targetHolder !== null && targetHolder !== void 0 && targetHolder.label) {
      str += "".concat(targetHolder.label, " \n");
    }
  }
  if (Array.isArray(multiResources) && multiResources.length > 0) {
    multiResources.forEach(function (resource) {
      var ids = resource.id,
        lists = resource.lists;
      if (Array.isArray(ids)) {
        ids.forEach(function (id) {
          var targetRes = lists.find(function (l) {
            return l.id === id;
          });
          if (targetRes !== null && targetRes !== void 0 && targetRes.label) str += "".concat(targetRes === null || targetRes === void 0 ? void 0 : targetRes.label, " \n");
        });
      } else {
        var targetRes = lists.find(function (l) {
          return l.id === ids;
        });
        if (targetRes !== null && targetRes !== void 0 && targetRes.label) str += "".concat(targetRes === null || targetRes === void 0 ? void 0 : targetRes.label, " \n");
      }
    });
  }

  // 组合规格 单规格
  if (product_option_string) str += "".concat(product_option_string, "\n");
  if (Array.isArray(options) && options.length) {
    options.forEach(function (opt) {
      str += "".concat(opt.name, "  ").concat(formatAmount(opt === null || opt === void 0 ? void 0 : opt.price, 2, currency_symbol), " x ").concat(opt.num, "\n");
    });
  }

  // 套餐
  if (Array.isArray(bundle) && bundle.length) {
    bundle.forEach(function (item) {
      str += "".concat(item.title, " \n");
      str += "".concat(formatAmount(item.price, 2, currency_symbol), " x ").concat(item.num);
    });
  }
  return str;
};
export default formatProductMessage;