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/enrichCacheItemBeforeAdd.ts
var enrichCacheItemBeforeAdd_exports = {};
__export(enrichCacheItemBeforeAdd_exports, {
  enrichCacheItemBeforeAdd: () => enrichCacheItemBeforeAdd
});
module.exports = __toCommonJS(enrichCacheItemBeforeAdd_exports);
var import_expandMultiDayCacheItem = require("./expandMultiDayCacheItem");
var import_buildBookingStateForAddFlow = require("./buildBookingStateForAddFlow");
var import_shouldPromptHolderOnAddCart = require("./shouldPromptHolderOnAddCart");
var import_applyHolderToCacheItem = require("./applyHolderToCacheItem");
var import_buildBookingEditDrawerState = require("../bookingEditService/buildBookingEditDrawerState");
var import_mergeCatalogDurationIntoCacheItem = require("./mergeCatalogDurationIntoCacheItem");
async function enrichCacheItemBeforeAdd(input) {
  var _a, _b, _c;
  let cacheItem = (0, import_mergeCatalogDurationIntoCacheItem.mergeCatalogDurationIntoCacheItem)(
    input.cacheItem,
    input.catalogItem ?? null
  );
  const customerId = (0, import_buildBookingEditDrawerState.resolveAddFlowCustomerId)(input.tempOrder, input.customerId);
  if ((0, import_shouldPromptHolderOnAddCart.shouldPromptHolderOnAddCart)({
    cacheItem,
    bookingConfig: input.bookingConfig,
    customerId
  })) {
    const openHolder = (_a = input.uiHosts) == null ? void 0 : _a.openHolderSelect;
    if (!openHolder) {
      if ((0, import_shouldPromptHolderOnAddCart.isHolderRequiredOnAddCart)(input.bookingConfig)) {
        return { status: "missing_host", missing: "holder" };
      }
    } else {
      const holderConfig = ((_b = input.bookingConfig) == null ? void 0 : _b.holder) || {};
      const holderIds = await openHolder({
        cacheItem,
        customerId,
        maxSelectedCount: (holderConfig == null ? void 0 : holderConfig.maxSelectedCount) || ((_c = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _c.quantity) || 1
      });
      if (holderIds && holderIds.length > 0) {
        cacheItem = (0, import_applyHolderToCacheItem.applyHolderToCacheItem)(cacheItem, holderIds);
      } else if ((0, import_shouldPromptHolderOnAddCart.isHolderRequiredOnAddCart)(input.bookingConfig)) {
        return { status: "cancelled" };
      }
    }
  }
  const bookingState = (0, import_buildBookingStateForAddFlow.buildBookingStateForAddFlow)({
    cacheItem,
    bookingConfig: input.bookingConfig,
    tempOrder: input.tempOrder,
    customerId,
    date: input.date,
    locale: input.locale,
    resourcesOrigin: []
  });
  try {
    cacheItem = await (0, import_expandMultiDayCacheItem.expandMultiDayCacheItem)(cacheItem, bookingState, {
      concatBookings: input.mode === "drawer",
      catalogItem: input.catalogItem ?? null
    });
  } catch (e) {
    console.warn("[SalesSdk] expandMultiDayCacheItem failed", e);
    return { status: "cancelled" };
  }
  return { status: "ok", cacheItem };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  enrichCacheItemBeforeAdd
});
