var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/salesSdk/utils/buildDefaultLoadProductsParams.ts
var buildDefaultLoadProductsParams_exports = {};
__export(buildDefaultLoadProductsParams_exports, {
  DEFAULT_BOOKING_CONFIG_PARAMS: () => DEFAULT_BOOKING_CONFIG_PARAMS,
  buildDefaultLoadProductsParams: () => buildDefaultLoadProductsParams,
  buildInitBookingContextParams: () => buildInitBookingContextParams,
  collectBookingIdsFromTempOrder: () => collectBookingIdsFromTempOrder,
  ensureBookingConfigForLoad: () => ensureBookingConfigForLoad,
  mergeLoadProductsParams: () => mergeLoadProductsParams,
  normalizeMenuListIds: () => normalizeMenuListIds
});
module.exports = __toCommonJS(buildDefaultLoadProductsParams_exports);
var import_dayjs = __toESM(require("dayjs"));
var DEFAULT_BOOKING_CONFIG_PARAMS = {
  item_type: "appointment_booking"
};
function collectBookingIdsFromTempOrder(tempOrder) {
  const bookings = tempOrder == null ? void 0 : tempOrder.bookings;
  if (!Array.isArray(bookings)) return [];
  return bookings.map((b) => b == null ? void 0 : b.id).filter((id) => typeof id === "number" && Number.isFinite(id));
}
function buildInitBookingContextParams(bookingConfigParams, options = {}) {
  var _a;
  return {
    bookingConfigParams: {
      ...DEFAULT_BOOKING_CONFIG_PARAMS,
      ...bookingConfigParams || {}
    },
    date: options.date ?? (0, import_dayjs.default)(),
    ...((_a = options.bookingIds) == null ? void 0 : _a.length) ? { bookingIds: options.bookingIds } : {},
    ...options.loadResources !== void 0 ? { loadResources: options.loadResources } : {}
  };
}
function normalizeMenuListIds(raw) {
  if (!Array.isArray(raw)) return [];
  const out = [];
  for (const item of raw) {
    const n = Number(item);
    if (Number.isFinite(n) && n > 0) out.push(Math.floor(n));
  }
  return [...new Set(out)];
}
function resolveScheduleFromDate(raw) {
  const date = raw && (0, import_dayjs.default)(raw).isValid() ? (0, import_dayjs.default)(raw) : (0, import_dayjs.default)();
  const schedule_date = date.format("YYYY-MM-DD");
  return {
    schedule_date,
    schedule_datetime: date.format(`${schedule_date} HH:mm:ss`)
  };
}
function buildDefaultLoadProductsParams(bookingTicket) {
  var _a, _b, _c, _d;
  const schedule = resolveScheduleFromDate(((_a = bookingTicket == null ? void 0 : bookingTicket.getBookingDate) == null ? void 0 : _a.call(bookingTicket)) ?? null);
  const bookingConfig = ((_b = bookingTicket == null ? void 0 : bookingTicket.getBookingConfig) == null ? void 0 : _b.call(bookingTicket)) ?? null;
  const menu_list_ids = normalizeMenuListIds(
    (_d = (_c = bookingConfig == null ? void 0 : bookingConfig.config) == null ? void 0 : _c.menu_list_tab) == null ? void 0 : _d.menu_list
  );
  return {
    ...schedule,
    ...menu_list_ids.length > 0 ? { menu_list_ids } : {}
  };
}
function mergeLoadProductsParams(defaults, override = {}) {
  const cleaned = Object.fromEntries(
    Object.entries(override).filter(([, value]) => value !== void 0)
  );
  return { ...defaults, ...cleaned };
}
async function ensureBookingConfigForLoad(bookingTicket, initParams) {
  var _a;
  if ((_a = bookingTicket.isBookingContextReady) == null ? void 0 : _a.call(bookingTicket, initParams)) return;
  if (typeof bookingTicket.initBookingContext === "function") {
    await bookingTicket.initBookingContext(initParams);
    return;
  }
  if (typeof bookingTicket.loadBookingConfig === "function") {
    await bookingTicket.loadBookingConfig(initParams.bookingConfigParams);
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DEFAULT_BOOKING_CONFIG_PARAMS,
  buildDefaultLoadProductsParams,
  buildInitBookingContextParams,
  collectBookingIdsFromTempOrder,
  ensureBookingConfigForLoad,
  mergeLoadProductsParams,
  normalizeMenuListIds
});
