/**
 * 计算 主页面购物车红点值
 * 数值为 整个数量 无论是否check
 * @param carList
 * return totalNumber
 */
const getCarTotalNum = (carList = []) => {
  if (!carList.length) return 0;
  return carList.reduce((pre, item) => pre + +item.quantity, 0);
};

const getBottom = (tabBarHight = 0) => {
  if (tabBarHight) {
    return +tabBarHight;
  } else {
    return 20;
  }
};

const hasSelected = (list) => {
  const selectedList = list.filter(v => v.checkedState === 'Y');
  return !!selectedList.length;
};

const isOnlyDeliver = (list = []) => {
  const selectedList = list.filter(v => v.checkedState === 'Y');
  if (!selectedList.length) {
    return false;
  }
  return selectedList.every(v => v.deliverType === 'DELIVERY');
};

export default {
  getBottom,
  hasSelected,
  isOnlyDeliver,
  getCarTotalNum,
};
