function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import dayjs from 'dayjs';
import { getIsEject, getIsOnlySession, isSessionProduct } from "../../../components/booking/utils";
import { getIsShowNumber } from "../../../components/ticketBooking/utils";
/**
 * 从资源编辑抽屉内的 cacheItem 构造 `openProductDetail` 入参（对齐 Info2 editService handleEdit）。
 *
 * @example
 * const payload = buildEditProductDetailPayload({
 *   cacheItem,
 *   bookingState,
 *   formValues: form.getFieldsValue(),
 * });
 * const detailResult = await uiHosts.openProductDetail?.(payload);
 */
export function buildEditProductDetailPayload(options) {
  var _bookingState$date$va, _bookingState$date, _bookingState$date$fo, _cacheItem$_extend4, _formValues$quantity, _cacheItem$_extend5, _options$customerId, _bookingState$client;
  var cacheItem = options.cacheItem,
    bookingState = options.bookingState,
    formValues = options.formValues;
  var isSession = isSessionProduct(cacheItem);
  var date = (_bookingState$date$va = (_bookingState$date = bookingState.date) === null || _bookingState$date === void 0 || (_bookingState$date = _bookingState$date.value) === null || _bookingState$date === void 0 || (_bookingState$date$fo = _bookingState$date.format) === null || _bookingState$date$fo === void 0 ? void 0 : _bookingState$date$fo.call(_bookingState$date, 'YYYY-MM-DD')) !== null && _bookingState$date$va !== void 0 ? _bookingState$date$va : dayjs().format('YYYY-MM-DD');
  var sessionValue = {};
  if (isSession) {
    var _cacheItem$_extend, _cacheItem$_extend2, _cacheItem$_extend3;
    sessionValue.startEndTime = {
      startDate: cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend = cacheItem._extend) === null || _cacheItem$_extend === void 0 ? void 0 : _cacheItem$_extend.start_date,
      endDate: cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend2 = cacheItem._extend) === null || _cacheItem$_extend2 === void 0 ? void 0 : _cacheItem$_extend2.end_date,
      duration: cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend3 = cacheItem._extend) === null || _cacheItem$_extend3 === void 0 ? void 0 : _cacheItem$_extend3.duration
    };
  }
  return {
    item: cacheItem,
    productData: _objectSpread(_objectSpread({}, cacheItem), {}, {
      initValue: _objectSpread(_objectSpread(_objectSpread({}, cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend4 = cacheItem._extend) === null || _cacheItem$_extend4 === void 0 ? void 0 : _cacheItem$_extend4.other), sessionValue), {}, {
        quantity: (_formValues$quantity = formValues.quantity) !== null && _formValues$quantity !== void 0 ? _formValues$quantity : cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend5 = cacheItem._extend) === null || _cacheItem$_extend5 === void 0 ? void 0 : _cacheItem$_extend5.quantity
      })
    }),
    showConfig: {
      option: true,
      session: isSession,
      variant: true,
      package: true,
      number: getIsShowNumber(cacheItem, bookingState)
    },
    isOnlySession: getIsOnlySession(cacheItem),
    isEject: getIsEject(cacheItem, 'detail') ? 1 : 0,
    customerId: (_options$customerId = options.customerId) !== null && _options$customerId !== void 0 ? _options$customerId : (_bookingState$client = bookingState.client) === null || _bookingState$client === void 0 || (_bookingState$client = _bookingState$client.value) === null || _bookingState$client === void 0 ? void 0 : _bookingState$client.id,
    date: date
  };
}