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/enrich.ts
var enrich_exports = {};
__export(enrich_exports, {
  enrichCartItem: () => enrichCartItem,
  enrichCartItems: () => enrichCartItems,
  enrichCustomer: () => enrichCustomer
});
module.exports = __toCommonJS(enrich_exports);
var import_selectors = require("../selectors");
var import_identity = require("./identity");
function enrichCartItem(line, ctx) {
  var _a, _b, _c, _d;
  const productUid = (_a = line.metadata) == null ? void 0 : _a.unique_identification_number;
  const matched = productUid ? (_c = (_b = ctx.bookingDetailMap) == null ? void 0 : _b[String(productUid)]) == null ? void 0 : _c[0] : void 0;
  const detail = matched == null ? void 0 : matched.detail;
  const productSummary = matched == null ? void 0 : matched.product;
  const catalog = ctx.productsCatalog.find(
    (p) => String(p.id) === String(line.product_id)
  );
  const variant = (_d = catalog == null ? void 0 : catalog.variants) == null ? void 0 : _d.find(
    (v) => (v == null ? void 0 : v.id) === line.product_variant_id
  );
  const detailBundles = Array.isArray(detail == null ? void 0 : detail.product_bundle) ? detail.product_bundle : [];
  const detailOptions = Array.isArray(detail == null ? void 0 : detail.product_option_item) ? detail.product_option_item : [];
  const catalogBundles = Array.isArray(catalog == null ? void 0 : catalog.bundles) ? catalog.bundles : [];
  const catalogOptions = Array.isArray(catalog == null ? void 0 : catalog.options) ? catalog.options : [];
  const bundleTitles = (line.product_bundle || []).map((b) => {
    const matchedDetail = detailBundles.find(
      (db) => (db == null ? void 0 : db.bundle_id) === (b == null ? void 0 : b.bundle_id)
    );
    if (matchedDetail == null ? void 0 : matchedDetail.title) return String(matchedDetail.title);
    const matchedCatalog = catalogBundles.find((cb) => (cb == null ? void 0 : cb.id) === (b == null ? void 0 : b.bundle_id));
    if (matchedCatalog == null ? void 0 : matchedCatalog.title) return String(matchedCatalog.title);
    return "";
  });
  const optionTitles = (line.product_option_item || []).map((o) => {
    const matchedDetail = detailOptions.find(
      (d) => (d == null ? void 0 : d.product_option_item_id) === (o == null ? void 0 : o.product_option_item_id)
    );
    if (matchedDetail == null ? void 0 : matchedDetail.title) return String(matchedDetail.title);
    const matchedCatalog = catalogOptions.find(
      (co) => (co == null ? void 0 : co.id) === (o == null ? void 0 : o.product_option_item_id)
    );
    if (matchedCatalog == null ? void 0 : matchedCatalog.title) return String(matchedCatalog.title);
    return "";
  });
  const startAt = matched && matched.start_date && matched.start_time ? `${matched.start_date} ${matched.start_time}` : null;
  const endAt = matched && matched.end_date && matched.end_time ? `${matched.end_date} ${matched.end_time}` : null;
  return {
    ...line,
    _identity: (0, import_identity.pickIdentity)(line),
    title: (detail == null ? void 0 : detail.product_title) ?? (catalog == null ? void 0 : catalog.title) ?? "",
    cover: (detail == null ? void 0 : detail.product_cover) ?? (catalog == null ? void 0 : catalog.cover) ?? "",
    variant_title: (detail == null ? void 0 : detail.variant_title) ?? (variant == null ? void 0 : variant.title) ?? "",
    bundle_titles: bundleTitles,
    option_titles: optionTitles,
    note: (detail == null ? void 0 : detail.note) ?? line.note ?? "",
    duration: (productSummary == null ? void 0 : productSummary.duration) ?? (catalog == null ? void 0 : catalog.duration),
    product_resource: (productSummary == null ? void 0 : productSummary.product_resource) ?? (catalog == null ? void 0 : catalog.product_resource),
    capacity: productSummary == null ? void 0 : productSummary.capacity,
    start_at: startAt,
    end_at: endAt,
    resource_id: (matched == null ? void 0 : matched.relation_id) ?? null
  };
}
function enrichCartItems(lines, ctx) {
  if (!Array.isArray(lines) || lines.length === 0) return [];
  return lines.map((line) => enrichCartItem(line, ctx));
}
function enrichCustomer(selected, tempOrder) {
  if (selected && selected.id !== void 0 && selected.id !== null && selected.id !== "" && selected.id !== 0) {
    return {
      id: selected.id,
      name: selected.name ?? "",
      phone: selected.phone,
      email: selected.email,
      country_calling_code: selected.country_calling_code,
      cover: selected.cover,
      isWalkIn: (0, import_selectors.isWalkInCustomer)(selected)
    };
  }
  if (tempOrder && (tempOrder.customer_id != null || tempOrder.customer_name)) {
    const id = tempOrder.customer_id ?? "";
    return {
      id,
      name: tempOrder.customer_name ?? "",
      phone: tempOrder.phone,
      email: tempOrder.email,
      country_calling_code: tempOrder.country_calling_code,
      cover: void 0,
      isWalkIn: (0, import_selectors.isWalkInCustomer)({ id })
    };
  }
  return null;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  enrichCartItem,
  enrichCartItems,
  enrichCustomer
});
