export function getGridClassName(grid) {
  let classNames = [];
  for (let k in grid) {
    classNames.push(`ant-col-${k}-${grid[k]}`);
  }
  return [].concat('ant-col', classNames);
}

export function computedGrid(grid) {
  const contentGrid = { xxl: 0, xl: 0, lg: 0, md: 0, sm: 0, xs: 0 };
  if (Array.isArray(grid)) {
    grid.forEach((item) => {
      for (let k in item) {
        if (contentGrid[k]) {
          contentGrid[k] = contentGrid[k] - item[k];
        } else {
          contentGrid[k] = 24 - item[k];
        }
      }
    });
  } else {
    for (let k in grid) {
      contentGrid[k] = 24 - grid[k];
    }
  }
  for (let k in contentGrid) {
    if (contentGrid[k] <= 0) {
      contentGrid[k] = 24;
    }
  }
  return contentGrid;
}

export function computedCuurentGrid() {
  const width = document.body.clientWidth;
  if (width >= 1600) {
    return 'xxl';
  }
  if (width >= 1200 && width < 1600) {
    return 'xl';
  }
  if (width >= 992 && width < 1200) {
    return 'lg';
  }
  if (width >= 768 && width < 992) {
    return 'md';
  }
  if (width >= 576 && width < 768) {
    return 'sm';
  }
  if (width < 576) {
    return 'xs';
  }
}
