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/formatHolderOptions.ts
var formatHolderOptions_exports = {};
__export(formatHolderOptions_exports, {
  formatHolderOptions: () => formatHolderOptions,
  mergeHolderOptions: () => mergeHolderOptions,
  normalizeHolderIds: () => normalizeHolderIds,
  resolveHolderLabels: () => resolveHolderLabels
});
module.exports = __toCommonJS(formatHolderOptions_exports);
function pickLabelFromRawItem(item) {
  const direct = (item == null ? void 0 : item.main_field) ?? (item == null ? void 0 : item.label) ?? (item == null ? void 0 : item.name) ?? (item == null ? void 0 : item.search_field) ?? "";
  if (String(direct).trim()) return String(direct).trim();
  return "";
  const skipKeys = /* @__PURE__ */ new Set([
    "form_record_id",
    "form_id",
    "id",
    "value",
    "status",
    "expired_at",
    "created_at",
    "relation_record",
    "search_field",
    "main_field",
    "avatar",
    "subtitle",
    "second_field",
    "sub_field",
    "form_to_form_value"
  ]);
  for (const [key, val] of Object.entries(item || {})) {
    if (skipKeys.has(key)) continue;
    if (typeof val === "string" && val.trim()) return val.trim();
  }
  return "";
}
function formatHolderOptions(rawHolders) {
  if (!Array.isArray(rawHolders) || rawHolders.length === 0) return [];
  console.log("xxxxxxxx rawHolders", rawHolders);
  return rawHolders.map((item) => {
    const id = (item == null ? void 0 : item.form_record_id) ?? (item == null ? void 0 : item.id) ?? (item == null ? void 0 : item.value);
    const label = pickLabelFromRawItem(item);
    if (id === void 0 || id === null || id === "") return null;
    return { id, label: String(label) };
  }).filter((item) => item != null);
}
function mergeHolderOptions(existing, incoming) {
  const map = /* @__PURE__ */ new Map();
  for (const option of existing) {
    map.set(String(option.id), option);
  }
  for (const option of incoming) {
    map.set(String(option.id), option);
  }
  return Array.from(map.values());
}
function normalizeHolderIds(value) {
  if (value === void 0 || value === null || value === "") return [];
  return Array.isArray(value) ? value : [value];
}
function resolveHolderLabels(holderIds, options) {
  return normalizeHolderIds(holderIds).map((id) => {
    const matched = options.find((option) => String(option.id) === String(id));
    return (matched == null ? void 0 : matched.label) || String(id);
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  formatHolderOptions,
  mergeHolderOptions,
  normalizeHolderIds,
  resolveHolderLabels
});
