import type { ColProps } from 'ant-design-vue';

export function useGridLayout(all: number): ColProps;
export function useGridLayout(xs: number, lg: number, xxl: number): ColProps;
export function useGridLayout(
  xs: number,
  sm: number,
  md: number,
  lg: number,
  xl: number,
  xxl: number
): ColProps;
export function useGridLayout(
  xs: number,
  sm?: number,
  md?: number,
  lg?: number,
  xl?: number,
  xxl?: number
): ColProps {
  const length = arguments.length;
  const maxCol = 24;

  const toCol = (number: number) => {
    return Math.floor(maxCol / number);
  };

  switch (length) {
    case 1:
      return { span: toCol(xs) };
    case 3:
      return { xs: toCol(xs), lg: toCol(sm!), xxl: toCol(md!) };
    case 6:
      return {
        xs: toCol(xs),
        sm: toCol(sm!),
        md: toCol(md!),
        lg: toCol(lg!),
        xl: toCol(xl!),
        xxl: toCol(xxl!),
      };
    default:
      return { span: toCol(xs) ?? 6 };
  }
}
