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/components/ticketBooking/utils/formatProductMessage.ts
var formatProductMessage_exports = {};
__export(formatProductMessage_exports, {
  default: () => formatProductMessage_default
});
module.exports = __toCommonJS(formatProductMessage_exports);
var import_utils = require("@pisell/utils");
var import_formatTime = require("./formatTime");
var import_utils2 = require("@pisell/utils");
var UNIT_LABEL = {
  KILOGRAMS: "kg",
  GRAMS: "g",
  POUNDS: "lb",
  OUNCES: "oz"
};
var DEFAULT_WEIGHT_PRECISION = 3;
var formatWeightValue = (value) => {
  const parsedValue = Number(value);
  const displayValue = Number.isFinite(parsedValue) ? parsedValue : 0;
  return displayValue.toFixed(DEFAULT_WEIGHT_PRECISION);
};
var formatProductMessage = (product, utils) => {
  var _a, _b;
  const {
    product_option_string,
    options,
    bundle,
    currency_symbol,
    start_date,
    end_date,
    holder_id,
    holders,
    multiResources
  } = product;
  let str = "";
  if (start_date && end_date) {
    str += `${(0, import_formatTime.getServiceTime)(product, start_date, utils)} 
`;
  }
  if (holder_id && Array.isArray(holders)) {
    const targetHolder = holders.find((holder) => holder.id === holder_id);
    if (targetHolder == null ? void 0 : targetHolder.label) {
      str += `${targetHolder.label} 
`;
    }
  }
  if (Array.isArray(multiResources) && multiResources.length > 0) {
    multiResources.forEach((resource) => {
      const { id: ids, lists } = resource;
      if (Array.isArray(ids)) {
        ids.forEach((id) => {
          const targetRes = lists.find((l) => l.id === id);
          if (targetRes == null ? void 0 : targetRes.label) str += `${targetRes == null ? void 0 : targetRes.label} 
`;
        });
      } else {
        const targetRes = lists.find((l) => l.id === ids);
        if (targetRes == null ? void 0 : targetRes.label) str += `${targetRes == null ? void 0 : targetRes.label} 
`;
      }
    });
  }
  const weighing = (_b = (_a = product == null ? void 0 : product._origin) == null ? void 0 : _a._extend) == null ? void 0 : _b.weighing;
  if (weighing) {
    const { mode, unit_price, unit, weight, tare, net_weight } = weighing;
    const unitLabel = UNIT_LABEL[unit] || unit;
    const weightText = formatWeightValue(weight);
    const tareText = formatWeightValue(tare == null ? void 0 : tare.value);
    const netWeightText = formatWeightValue(net_weight);
    const tareValue = Number((tare == null ? void 0 : tare.value) || 0);
    const isManualWeight = mode === "manual";
    const unitPriceText = `${currency_symbol || ""}${unit_price ?? "0.00"}`;
    const manualPrefix = isManualWeight ? "(M) " : "";
    if (tareValue > 0) {
      str += `${manualPrefix}${import_utils2.locales.getText("pisell2.cart.sku-card.weighing.gross")}: ${weightText} ${unitLabel} 
`;
    }
    if (tareValue > 0) {
      str += `${import_utils2.locales.getText("pisell2.cart.sku-card.weighing.tare")}: ${tareText} ${UNIT_LABEL[tare == null ? void 0 : tare.unit] || (tare == null ? void 0 : tare.unit) || unitLabel} 
`;
    }
    str += `${tareValue > 0 ? "" : manualPrefix}${netWeightText} ${unitLabel} ${import_utils2.locales.getText("pisell2.cart.sku-card.weighing.net")} @ ${unitPriceText}/${unitLabel} 
`;
  }
  if (product_option_string) str += `${product_option_string}
`;
  if (Array.isArray(options) && options.length) {
    options.forEach((opt) => {
      str += `${opt.name}  ${(0, import_utils.formatAmount)(opt == null ? void 0 : opt.price, 2, currency_symbol)} x ${opt.num}
`;
    });
  }
  if (Array.isArray(bundle) && bundle.length) {
    bundle.forEach((item) => {
      str += `${item.title}  ${(0, import_utils.formatAmount)(item.price, 2, currency_symbol)} x ${item.num}
`;
      const bundleOptions = item == null ? void 0 : item.options;
      if (Array.isArray(bundleOptions) && bundleOptions.length) {
        bundleOptions.forEach((opt) => {
          str += `  ${opt == null ? void 0 : opt.name}  ${(0, import_utils.formatAmount)(opt == null ? void 0 : opt.price, 2, currency_symbol)} x ${opt == null ? void 0 : opt.num}
`;
        });
      }
    });
  }
  return str;
};
var formatProductMessage_default = formatProductMessage;
