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); }
/**
 * @title: 套餐单规格信息
 * @description:
 * @param {any} option
 * @return {*}
 * @Author: zhiwei.Wang
 * @Date: 2024-02-19 09:26
 */
export var formatProductOption = function formatProductOption(option) {
  if (!option) {
    return [];
  }
  return option.map(function (d) {
    return {
      num: d.num,
      option_group_item_id: d.product_option_item_id,
      option_group_id: d.option_group_id
    };
  });
};

/**
 * @title: 套餐信息
 * @description:
 * @param {any} bundle
 * @return {*}
 * @Author: zhiwei.Wang
 * @Date: 2024-02-19 09:26
 */
export var formatProductBundle = function formatProductBundle(bundle) {
  if (!bundle) {
    return;
  }
  return bundle.map(function (d) {
    return {
      bundle_group_id: d.group_id,
      bundle_id: d.id,
      bundle_product_id: d._bundle_product_id,
      bundle_variant_id: d.bundle_variant_id,
      num: d.num,
      extension_id: d.extension_id,
      extension_type: d.extension_type,
      option: formatProductOption(d.option)
    };
  });
};
var getSubType = function getSubType(item) {
  var _item$duration;
  var _type = (_item$duration = item.duration) === null || _item$duration === void 0 ? void 0 : _item$duration.type;
  // 目前不支持跨天
  if (_type && _type !== 'days') {
    return _type;
  }
  return 'minutes';
};

/**
 * @title: 预约商品信息
 * @description:
 * @param {any} data
 * @return {*}
 * @Author: zhiwei.Wang
 * @Date: 2024-02-19 09:26
 */
var formatBookings = function formatBookings(list) {
  var bookings = [];
  bookings = list.map(function (item) {
    return item._originData;
  });
  return bookings;
};

/**
 * @title: 格式化下单接口数据
 * @description:
 * @param {any} state saledModel数据源
 * @param {boolean} excludeDisabled 是否需要排除购物车中失效商品
 * @Author: xiangfeng.xue
 * @Date: 2025-01-21 17:57
 */
export var formatValues = function formatValues(params) {
  var state = params.state,
    otherValue = params.otherValue,
    platform = params.platform,
    excludeDisabled = params.excludeDisabled,
    extra = params.extra;
  var values = _objectSpread(_objectSpread({
    type: 'event_booking_v2',
    platform: platform === 'pc' ? 'PC' : 'H5',
    sales_channel: 'my_pisel',
    order_sales_channel: 'online_store',
    bookings: [],
    shop_note: '',
    schedule_date: ''
  }, extra || {}), otherValue || {});
  console.log('values', values);
  var data = [];
  if (excludeDisabled) {
    var _state$cartData$cartI, _state$cartData$cartI2;
    data = (_state$cartData$cartI = state.cartData.cartItems) === null || _state$cartData$cartI === void 0 || (_state$cartData$cartI2 = _state$cartData$cartI.filter) === null || _state$cartData$cartI2 === void 0 ? void 0 : _state$cartData$cartI2.call(_state$cartData$cartI, function (v) {
      return v.disabled !== true;
    });
  } else {
    data = state.cartData.cartItems;
  }

  // 定金
  var is_deposit = data.find(function (v) {
    return v.deposit;
  }) ? 1 : 0;
  values.is_deposit = is_deposit;

  // 服务
  values.bookings = formatBookings(data);
  return values;
};

/**
 * @title: 获取拉开表单弹窗参数
 * @param state
 */
export var getFormParams = function getFormParams(state) {
  var _state$cartData;
  var product_id = ((state === null || state === void 0 || (_state$cartData = state.cartData) === null || _state$cartData === void 0 ? void 0 : _state$cartData.cartItems) || []).map(function (item) {
    var _item$_originData;
    return (_item$_originData = item._originData) === null || _item$_originData === void 0 || (_item$_originData = _item$_originData.product) === null || _item$_originData === void 0 ? void 0 : _item$_originData.product_id;
  });
  return {
    product_id: product_id,
    appointment_type: 'event_booking_v2'
  };
};