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/pisellReservation/utils/seedDineInReservationToCart.ts
var seedDineInReservationToCart_exports = {};
__export(seedDineInReservationToCart_exports, {
  seedDineInReservationToCart: () => seedDineInReservationToCart
});
module.exports = __toCommonJS(seedDineInReservationToCart_exports);
var import_dayjs = __toESM(require("dayjs"));
var import_prepareCacheItemForBookingEdit = require("../../salesSdk/bookingEditService/prepareCacheItemForBookingEdit");
var import_enrichCacheItemBeforeAdd = require("../../salesSdk/utils/enrichCacheItemBeforeAdd");
var import_reservationTicketBookingHostParams = require("./reservationTicketBookingHostParams");
async function seedDineInReservationToCart(input) {
  const {
    bookingTicket,
    reservationRuleProduct,
    row,
    appointmentStatus = "started",
    bookingConfig,
    tempOrder,
    customerId,
    locale,
    uiHosts
  } = input;
  if (!bookingTicket) {
    throw new Error("[seedDineInReservationToCart] bookingTicket 未初始化");
  }
  if (typeof bookingTicket.transformDetailToProductAndBooking !== "function") {
    throw new Error(
      "[seedDineInReservationToCart] transformDetailToProductAndBooking 不可用"
    );
  }
  if (typeof bookingTicket.addProductToOrder !== "function") {
    throw new Error("[seedDineInReservationToCart] addProductToOrder 不可用");
  }
  const date = input.date || (0, import_dayjs.default)().format("YYYY-MM-DD");
  const resourcePayload = (0, import_reservationTicketBookingHostParams.buildResourcePayloadFromReservationRow)(row);
  let cacheItem = (0, import_reservationTicketBookingHostParams.buildServiceItemFromReservationRuleProduct)(
    reservationRuleProduct,
    resourcePayload
  );
  cacheItem = (0, import_prepareCacheItemForBookingEdit.prepareCacheItemForBookingEdit)(cacheItem);
  const enriched = await (0, import_enrichCacheItemBeforeAdd.enrichCacheItemBeforeAdd)({
    cacheItem,
    catalogItem: reservationRuleProduct,
    uiHosts,
    bookingConfig,
    tempOrder,
    customerId,
    date,
    locale,
    mode: "direct"
  });
  if (enriched.status !== "ok") {
    throw new Error(
      `[seedDineInReservationToCart] enrich 失败: ${enriched.status}`
    );
  }
  const transformed = bookingTicket.transformDetailToProductAndBooking({
    item: reservationRuleProduct,
    cacheItem: enriched.cacheItem,
    options: { quantity: 1, date }
  });
  const bookingWithStatus = transformed.booking ? {
    ...transformed.booking,
    appointment_status: appointmentStatus
  } : void 0;
  return bookingTicket.addProductToOrder(transformed.product, bookingWithStatus);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  seedDineInReservationToCart
});
