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/mergeCatalogDurationIntoCacheItem.ts
var mergeCatalogDurationIntoCacheItem_exports = {};
__export(mergeCatalogDurationIntoCacheItem_exports, {
  mergeCatalogDurationIntoCacheItem: () => mergeCatalogDurationIntoCacheItem
});
module.exports = __toCommonJS(mergeCatalogDurationIntoCacheItem_exports);
function resolveTopLevelDurationFromBooking(booking) {
  const raw = booking == null ? void 0 : booking.duration;
  if (raw == null || raw === "") return null;
  if (typeof raw === "object" && raw.type) return raw;
  const subType = (booking == null ? void 0 : booking.sub_type) === "days" ? "days" : "minutes";
  const value = Number(raw);
  if (!Number.isFinite(value) || value <= 0) return null;
  return { type: subType, value };
}
function mergeCatalogDurationIntoCacheItem(cacheItem, catalogItem, booking) {
  var _a, _b;
  if ((_a = cacheItem == null ? void 0 : cacheItem.duration) == null ? void 0 : _a.type) {
    return cacheItem;
  }
  if (catalogItem == null ? void 0 : catalogItem.duration) {
    return {
      ...cacheItem,
      duration: catalogItem.duration
    };
  }
  const extDuration = (_b = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _b.duration;
  if (typeof extDuration === "object" && (extDuration == null ? void 0 : extDuration.type)) {
    return { ...cacheItem, duration: extDuration };
  }
  if (typeof extDuration === "number" && extDuration > 0) {
    return {
      ...cacheItem,
      duration: {
        type: "minutes",
        value: extDuration
      }
    };
  }
  const bookingDuration = resolveTopLevelDurationFromBooking(booking);
  if (bookingDuration) {
    return { ...cacheItem, duration: bookingDuration };
  }
  return cacheItem;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  mergeCatalogDurationIntoCacheItem
});
