import type { TableColumnProps, PaginationProps, BasicTableProps } from '@/types/basic-table';
import { DEFAULT_PAGE_SIZE } from '@/constant/pagination';
import { reactive } from 'vue';

/**
 * 表格配置hook
 * @param columns 表格列配置
 * @param options 表格选项配置 element-plus表格配置
 * @example
 * const { tableConfig, pagination } = useTableConfig(columns, options);
 * @returns 表格配置项和分页处理方法
 * @description 用于BasicTable组件的配置
 * @author Chauncey
 */
const useTableConfig = (columns: TableColumnProps[], options: any = {}) => {
  // 分页配置
  const pagination = reactive<PaginationProps>({
    total: 0,
    pageSize: DEFAULT_PAGE_SIZE,
    pageNumber: 1,
  });

  // 表格配置
  const tableConfig = reactive<BasicTableProps>({
    columns,
    pagination,
    ...options,
  });

  return {
    tableConfig,
    pagination,
  };
};

export default useTableConfig;
