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/solution/BookingTicket/utils/bookingStatus.ts
var bookingStatus_exports = {};
__export(bookingStatus_exports, {
  applyBookingsStatus: () => applyBookingsStatus,
  resolveScheduleId: () => resolveScheduleId,
  restoreBookingsStatus: () => restoreBookingsStatus
});
module.exports = __toCommonJS(bookingStatus_exports);
function resolveScheduleId(tempOrder) {
  var _a;
  if (!tempOrder)
    return null;
  const metaScheduleId = (_a = tempOrder.metadata) == null ? void 0 : _a.appointment_booking_parent_schedule_id;
  if (metaScheduleId !== void 0 && metaScheduleId !== null) {
    return metaScheduleId;
  }
  const bookings = Array.isArray(tempOrder.bookings) ? tempOrder.bookings : [];
  const rootBooking = bookings.find((b) => (b == null ? void 0 : b.parent_id) === 0);
  const fallback = rootBooking == null ? void 0 : rootBooking.schedule_event_id;
  return fallback !== void 0 && fallback !== null ? fallback : null;
}
function applyBookingsStatus(bookings, status) {
  if (!Array.isArray(bookings))
    return [];
  const previous = bookings.map((b) => b == null ? void 0 : b.appointment_status);
  bookings.forEach((b) => {
    if (b)
      b.appointment_status = status;
  });
  return previous;
}
function restoreBookingsStatus(bookings, previous) {
  if (!Array.isArray(bookings))
    return;
  const len = Math.min(bookings.length, previous.length);
  for (let i = 0; i < len; i += 1) {
    const b = bookings[i];
    if (b)
      b.appointment_status = previous[i];
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  applyBookingsStatus,
  resolveScheduleId,
  restoreBookingsStatus
});
