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} state
 * @return {*}
 * @Author: WangHan
 * @Date: 2024-11-28 16:52
 */
export var formatCartList = function formatCartList(state) {
  var products = state.products,
    holders = state.holders;
  return holders === null || holders === void 0 ? void 0 : holders.map(function (holder) {
    return _objectSpread(_objectSpread({}, holder), {}, {
      products: products === null || products === void 0 ? void 0 : products.filter(function (product) {
        return (product === null || product === void 0 ? void 0 : product.holder_id) === (holder === null || holder === void 0 ? void 0 : holder.key);
      })
    });
  });
};

/**
 * @title: 是否是空页面
 * @description: 
 * @param {any} state
 * @return {*}
 * @Author: WangHan
 * @Date: 2024-11-28 16:47
 */
export var isEmptyStatus = function isEmptyStatus(state) {
  var products = state.products,
    holders = state.holders,
    isOpenGroup = state.isOpenGroup;
  // 没开启分组并且没有商品数据
  if (!isOpenGroup && !(products !== null && products !== void 0 && products.length)) return true;

  // 开启分组没有holders
  if (isOpenGroup && !(holders !== null && holders !== void 0 && holders.length)) return true;
  return false;
};

/**
 * @title: 是否是商品列表页面
 * @description: 
 * @param {any} state
 * @return {*}
 * @Author: WangHan
 * @Date: 2024-11-28 17:23
 */
export var isProductList = function isProductList(state) {
  var holders = state.holders,
    isOpenGroup = state.isOpenGroup;

  // 开启分组并且有holders, 则是购物车列表
  if (isOpenGroup && holders !== null && holders !== void 0 && holders.length) return false;
  return true;
};

/**
 * @title: 格式化数据最终结果
 * @description: 
 * @param {any} state
 * @return {*}
 * @Author: WangHan
 * @Date: 2024-11-28 18:35
 */
export var formatState = function formatState(state) {
  // 默认数据格式化holder数据
  var _default = _objectSpread({}, state);
  var _carts = formatCartList(_default);
  return {
    isEmpty: isEmptyStatus(_default),
    isProductList: isProductList(_default),
    carts: _carts
  };
};

/**
 * @title: 更新商品
 * @description: 
 * @param {any} newState
 * @param {any} state
 * @return {*}
 * @Author: WangHan
 * @Date: 2024-11-28 22:30
 */
export var updateProduct = function updateProduct(state, newProducts) {
  return {
    products: newProducts,
    carts: formatCartList(_objectSpread(_objectSpread({}, state), {}, {
      products: newProducts
    }))
  };
};

/**
 * @title: 格式化服务
 * @description: 
 * @param {any} service
 * @param {number} id holder_id
 * @return {*}
 * @Author: WangHan
 * @Date: 2024-12-09 22:47
 */
export var formatService = function formatService(service, id) {
  return service.map(function (item) {
    return _objectSpread(_objectSpread({}, item), {}, {
      holder_id: id
    });
  });
};