/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2022-12-20 15:24:11
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2023-11-22 16:36:30
 * @FilePath: /BudgetManaSystem/src/components/BMSTable/index.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ProTable, ProTableProps } from '@ant-design/pro-components';
import { useMemo } from 'react';

import './style.less';

export type KCIMTablePropsType<T, U, ValueType> = ProTableProps<
  T,
  U,
  ValueType
> & {};

export const KCIMTablePageDefaultConfig = {
  defaultPageSize: 10,
};

export const KCIMTable = (props: KCIMTablePropsType<any, any, any>) => {
  const { params, options = false, request, columns, ...rest } = props;
  const mergedColumns = useMemo(
    () => columns?.map((column) => ({ ...column, ellipsis: true })),
    [columns],
  );
  const mergedParams = useMemo(
    () => (params ? { ...params } : params),
    [params],
  );
  const wrappedRequest = useMemo(() => {
    if (!request) return undefined;
    return (requestParams: any, sort: any, filter: any) =>
      request({ ...requestParams }, sort, filter);
  }, [request]);

  return (
    <ProTable
      tableClassName="KCIMTable"
      toolBarRender={false}
      options={options}
      columns={mergedColumns}
      pagination={{
        showSizeChanger: true,
        ...KCIMTablePageDefaultConfig,
      }}
      //locale={{emptyText:'暂无数据'}}
      params={mergedParams}
      bordered={false}
      search={false}
      tableStyle={{
        border: '1px solid #DAE2F2',
        borderRadius: '8px',
      }}
      request={wrappedRequest}
      {...rest}
    />
  );
};
