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/solution/BookingTicket/utils/scan/scanProductValues.ts
var scanProductValues_exports = {};
__export(scanProductValues_exports, {
  countScanVariantMatches: () => countScanVariantMatches,
  genScanProductValues: () => genScanProductValues,
  isScanProductBundle: () => isScanProductBundle,
  isScanProductOption: () => isScanProductOption
});
module.exports = __toCommonJS(scanProductValues_exports);
function isScanProductBundle(item) {
  return ((item == null ? void 0 : item.bundle_group_count) || 0) > 0;
}
function isScanProductOption(item) {
  var _a;
  return ((item == null ? void 0 : item.option_group_count) || 0) > 0 || (((_a = item == null ? void 0 : item.option_group) == null ? void 0 : _a.length) || 0) > 0;
}
function formatVariantGroupTitle(title, variantGroup = []) {
  try {
    return variantGroup.map((group) => {
      const value = title == null ? void 0 : title[group == null ? void 0 : group.position_id];
      return value ? `${(group == null ? void 0 : group.name) || "-"}: ${value}` : "";
    }).filter(Boolean).join(", ");
  } catch {
    return "";
  }
}
function formatDataKey(data) {
  var _a, _b, _c, _d;
  const next = { ...data };
  let key = `${next.product_id}`;
  let rowKey = key;
  if (next.product_variant_id) {
    const str = `_${next.product_variant_id}`;
    key += str;
    rowKey += str;
  }
  if ((_a = next == null ? void 0 : next.option) == null ? void 0 : _a.length) {
    for (const item of next.option) {
      const str = `_${item.option_group_id}_${item.product_option_item_id}`;
      key += str;
      rowKey += `${str}_${item.quantity || item.num}`;
    }
  }
  if ((_b = next == null ? void 0 : next.bundle) == null ? void 0 : _b.length) {
    for (const item of next.bundle) {
      let str = `_${item.group_id}_${item.bundle_product_id}`;
      key += str;
      rowKey += `${str}_${item.quantity || item.num}`;
      if (item == null ? void 0 : item.option) {
        for (const opt of item.option) {
          const optStr = `_${opt.option_group_id}_${opt.product_option_item_id}`;
          key += optStr;
          rowKey += `${optStr}_${opt.quantity || opt.num}`;
        }
      }
    }
  }
  if (next == null ? void 0 : next.session) {
    const str = `_${(_c = next.session) == null ? void 0 : _c.key}`;
    key += str;
    rowKey += str;
  }
  if (next == null ? void 0 : next.schedule) {
    const str = `_${(_d = next.schedule) == null ? void 0 : _d.key}`;
    key += str;
    rowKey += str;
  }
  next.key = key;
  next.rowKey = rowKey;
  return next;
}
function genScanProductValues(item, code) {
  var _a, _b;
  const params = {
    bundle: [],
    option: [],
    product_id: item.id,
    product_variant_id: 0,
    quantity: 1,
    rowKey: "",
    session: null
  };
  if (((_a = item == null ? void 0 : item.variant_group) == null ? void 0 : _a.length) || ((_b = item == null ? void 0 : item.option_group) == null ? void 0 : _b.length)) {
    const variantItem = (item.variant || []).find(
      (v) => (v == null ? void 0 : v.code) === code || (v == null ? void 0 : v.barcode) === code
    );
    if (variantItem) {
      params.price = Number((variantItem == null ? void 0 : variantItem.price) || 0);
      params.product_variant_id = variantItem.id;
      params.product_option_string = formatVariantGroupTitle(
        variantItem == null ? void 0 : variantItem.title,
        (item == null ? void 0 : item.variant_group) || []
      );
    }
  }
  return formatDataKey(params);
}
function countScanVariantMatches(item, code) {
  return ((item == null ? void 0 : item.variant) || []).filter(
    (v) => (v == null ? void 0 : v.code) === code || (v == null ? void 0 : v.barcode) === code
  ).length;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  countScanVariantMatches,
  genScanProductValues,
  isScanProductBundle,
  isScanProductOption
});
