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/applyHolderToCacheItem.ts
var applyHolderToCacheItem_exports = {};
__export(applyHolderToCacheItem_exports, {
  applyHolderToCacheItem: () => applyHolderToCacheItem,
  buildBookingHolder: () => buildBookingHolder,
  normalizeSelectedHolderIds: () => normalizeSelectedHolderIds,
  resolveHolderFormId: () => resolveHolderFormId,
  resolveHolderName: () => resolveHolderName
});
module.exports = __toCommonJS(applyHolderToCacheItem_exports);
function normalizeSelectedHolderIds(holderIds) {
  if (Array.isArray(holderIds)) {
    return holderIds.filter((id) => id !== void 0 && id !== null && id !== "");
  }
  if (holderIds === void 0 || holderIds === null || holderIds === "") {
    return [];
  }
  return [holderIds];
}
function resolveHolderFormId(bookingConfig) {
  var _a, _b, _c, _d, _e, _f;
  return ((_c = (_b = (_a = bookingConfig == null ? void 0 : bookingConfig.config) == null ? void 0 : _a.basic) == null ? void 0 : _b.appointment_subject) == null ? void 0 : _c.form_id) ?? ((_e = (_d = bookingConfig == null ? void 0 : bookingConfig.holder) == null ? void 0 : _d.form) == null ? void 0 : _e.id) ?? ((_f = bookingConfig == null ? void 0 : bookingConfig.holder) == null ? void 0 : _f.form_id) ?? 0;
}
function resolveHolderName(holderIds, holderOptions = []) {
  const optionMap = new Map(
    holderOptions.map((option) => [String(option.id), option.label])
  );
  const names = normalizeSelectedHolderIds(holderIds).map((id) => optionMap.get(String(id))).filter((label) => Boolean(label));
  return names.length ? names.join(",") : void 0;
}
function buildBookingHolder(holderIds, options = {}) {
  const holder = {
    customer_id: options.customerId,
    form_id: resolveHolderFormId(options.bookingConfig),
    form_record: normalizeSelectedHolderIds(holderIds)
  };
  const holderName = resolveHolderName(holderIds, options.holderOptions);
  if (holderName) {
    holder.name = holderName;
  }
  if (options.isFranchisee) {
    holder.is_source_shop = 1;
  }
  return holder;
}
function applyHolderToCacheItem(cacheItem, holderIds, options = {}) {
  const normalizedHolderIds = normalizeSelectedHolderIds(holderIds);
  return {
    ...cacheItem,
    _extend: {
      ...cacheItem._extend,
      holder_id: normalizedHolderIds,
      holder: buildBookingHolder(normalizedHolderIds, options)
    }
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  applyHolderToCacheItem,
  buildBookingHolder,
  normalizeSelectedHolderIds,
  resolveHolderFormId,
  resolveHolderName
});
