
import { RaxNode } from 'rax';
import { StyledComponentProps } from '@rax-ui/styles';

export type CompareFn = ((a: any, b: any, sortOrder?: SortOrder) => number);
export type SortOrder = 'descend' | 'ascend' | null;

export interface TableLocale {
  emptyText?: string
} 

export interface ColumnProps extends StyledComponentProps<any> {
  key: string;
  dataIndex?: string; 
  render?: (text: any, record: any, index: number) => RaxNode;
  align?: 'left' | 'right' | 'center';
  sorter?: boolean | CompareFn;
  defaultSortOrder?: SortOrder;
  width?: string | number;
  fixed?: boolean | ('left' | 'right');
  sortOrder?: SortOrder;
  desc?: string;
  children?: ColumnProps[];
  onCell?: (record: any, rowIndex: number) => any;
  onHeaderCell?: (props: ColumnProps) => any;
  sortDirections?: SortOrder[];
}

export interface TableProps extends StyledComponentProps<any> {
  dataSource?: [];
  columns: ColumnProps[];
  locale?: TableLocale;
  customStyles?: (defaultStyles: any) => any;
  onClickDescIcon?: (column: ColumnProps, event: Event) => void;
  descIconRender?: (column: ColumnProps) => RaxNode;
  sortIconRender?: (column: ColumnProps, sortOrder: string) => RaxNode;
  onChange?: (column: ColumnProps) => void;
  onRow?: (record: any, index: number) => any;
  onHeaderRow?: (columns: ColumnProps[], index: number) => any;
  bordered?: boolean;
  sortDirections?: SortOrder[];
}