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/enrichCartLineHolderDisplay.ts
var enrichCartLineHolderDisplay_exports = {};
__export(enrichCartLineHolderDisplay_exports, {
  buildHolderListRequestParams: () => buildHolderListRequestParams,
  enrichCartBookingHolderDisplay: () => enrichCartBookingHolderDisplay,
  formatHolderOptions: () => import_formatHolderOptions.formatHolderOptions,
  pickHolderIdFromBooking: () => pickHolderIdFromBooking,
  resolveHolderDisplayConfig: () => resolveHolderDisplayConfig
});
module.exports = __toCommonJS(enrichCartLineHolderDisplay_exports);
var import_formatHolderOptions = require("./formatHolderOptions");
function resolveHolderDisplayConfig(bookingConfig) {
  var _a, _b, _c, _d, _e;
  return {
    isFormSubject: ((_c = (_b = (_a = bookingConfig == null ? void 0 : bookingConfig.config) == null ? void 0 : _a.basic) == null ? void 0 : _b.appointment_subject) == null ? void 0 : _c.type) === "form",
    holderType: ((_e = (_d = bookingConfig == null ? void 0 : bookingConfig.holder) == null ? void 0 : _d.form) == null ? void 0 : _e.form_type) || "minors"
  };
}
function pickHolderIdFromBooking(booking) {
  var _a, _b, _c, _d, _e, _f, _g;
  return (booking == null ? void 0 : booking.holder_id) ?? ((_a = booking == null ? void 0 : booking.metadata) == null ? void 0 : _a.holder_id) ?? ((_d = (_c = (_b = booking == null ? void 0 : booking._extend) == null ? void 0 : _b.product) == null ? void 0 : _c.metadata) == null ? void 0 : _d.holder_id) ?? ((_g = (_f = (_e = booking == null ? void 0 : booking._extend) == null ? void 0 : _e.product) == null ? void 0 : _f._extend) == null ? void 0 : _g.holder_id) ?? null;
}
function enrichCartBookingHolderDisplay(booking, ctx) {
  var _a;
  const holder_id = pickHolderIdFromBooking(booking);
  const productLine = (_a = booking._extend) == null ? void 0 : _a.product;
  const holderMaxCount = Number(
    (productLine == null ? void 0 : productLine.num) ?? (productLine == null ? void 0 : productLine.product_quantity) ?? (0, import_formatHolderOptions.normalizeHolderIds)(holder_id).length
  ) || 1;
  return {
    ...booking,
    holder_id,
    holderOptions: ctx.holderOptions,
    holders: ctx.holderOptions,
    isFormSubject: ctx.displayConfig.isFormSubject,
    holderType: ctx.displayConfig.holderType,
    holderMaxCount
  };
}
function buildHolderListRequestParams(input) {
  var _a, _b, _c, _d;
  const { bookingConfig, customerId } = input;
  const holder = bookingConfig == null ? void 0 : bookingConfig.holder;
  if (!((_a = holder == null ? void 0 : holder.form) == null ? void 0 : _a.id) && !(holder == null ? void 0 : holder.form_id)) return null;
  const appointmentSubject = ((_c = (_b = bookingConfig == null ? void 0 : bookingConfig.config) == null ? void 0 : _b.basic) == null ? void 0 : _c.appointment_subject) || {};
  if (!appointmentSubject.form_id) return null;
  return {
    form_id: appointmentSubject.form_id,
    source_shop_customer: (_d = holder == null ? void 0 : holder.form) == null ? void 0 : _d.is_franchisor,
    customer_id: (holder == null ? void 0 : holder.data_range) === "customer" ? customerId : void 0,
    skip: 1,
    num: 100
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildHolderListRequestParams,
  enrichCartBookingHolderDisplay,
  formatHolderOptions,
  pickHolderIdFromBooking,
  resolveHolderDisplayConfig
});
