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/bookingEditService/buildEditProductDetailPayload.ts
var buildEditProductDetailPayload_exports = {};
__export(buildEditProductDetailPayload_exports, {
  buildEditProductDetailPayload: () => buildEditProductDetailPayload
});
module.exports = __toCommonJS(buildEditProductDetailPayload_exports);
var import_dayjs = __toESM(require("dayjs"));
var import_utils = require("../../../components/booking/utils");
var import_utils2 = require("../../../components/ticketBooking/utils");
function buildSessionStartEndTime(cacheItem) {
  var _a;
  const extend = (cacheItem == null ? void 0 : cacheItem._extend) || {};
  const session = ((_a = extend == null ? void 0 : extend.other) == null ? void 0 : _a.session) || {};
  const startDate = (0, import_dayjs.default)(extend.start_date);
  const endDate = (0, import_dayjs.default)(extend.end_date);
  const startAt = (session == null ? void 0 : session.start_at) ?? (startDate.isValid() && extend.start_time ? (0, import_dayjs.default)(`${startDate.format("YYYY-MM-DD")} ${extend.start_time}`) : extend.start_date);
  const endAt = (session == null ? void 0 : session.end_at) ?? (endDate.isValid() && extend.end_time ? (0, import_dayjs.default)(`${endDate.format("YYYY-MM-DD")} ${extend.end_time}`) : extend.end_date);
  return {
    startDate: startAt,
    endDate: endAt,
    duration: extend.duration
  };
}
function buildEditProductDetailPayload(options) {
  var _a, _b, _c, _d, _e, _f, _g;
  const { cacheItem, bookingState, formValues } = options;
  const isSession = (0, import_utils.isSessionProduct)(cacheItem);
  const date = ((_c = (_b = (_a = bookingState.date) == null ? void 0 : _a.value) == null ? void 0 : _b.format) == null ? void 0 : _c.call(_b, "YYYY-MM-DD")) ?? (0, import_dayjs.default)().format("YYYY-MM-DD");
  const sessionValue = {};
  if (isSession) {
    sessionValue.startEndTime = buildSessionStartEndTime(cacheItem);
  }
  const initQuantity = formValues.quantity ?? ((_d = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _d.quantity);
  return {
    item: cacheItem,
    productData: {
      ...cacheItem,
      initValue: {
        ...(_e = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _e.other,
        ...sessionValue,
        quantity: initQuantity
      }
    },
    showConfig: {
      option: true,
      session: isSession,
      variant: true,
      package: true,
      number: (0, import_utils2.getIsShowNumber)(cacheItem, bookingState)
    },
    isOnlySession: (0, import_utils.getIsOnlySession)(cacheItem),
    isEject: (0, import_utils.getIsEject)(cacheItem, "detail") ? 1 : 0,
    customerId: options.customerId ?? ((_g = (_f = bookingState.client) == null ? void 0 : _f.value) == null ? void 0 : _g.id),
    date
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildEditProductDetailPayload
});
