import type { ColumnDef, PaginationState, RowSelectionState, SortingState } from "@tanstack/react-table";
import type { ReactNode } from "react";
import { PaginationController } from "../hooks/useAppPagination";

export type Appearance = "default" | "card" | "minimal";
export type TableSize = "sm" | "md" | "lg";
export type DataTableColumnDef<TData extends object> = ColumnDef<TData, unknown>;
export type TableSortingState = SortingState;
export type TablePaginationState = PaginationState;

export interface TableClassNames {
  root?: string;

  toolbar?: string;
  filters?: string;

  table?: string;

  tableThead?: string;
  tableTheadRow?: string;
  tableTheadCell?: string;

  tableTbody?: string;
  tableTbodyRow?: string;
  tableTbodyCell?: string;

  pagination?: string;
}

export interface PaginationConfig {
  controller: PaginationController;

  totalItems: number;

  pageCount: number;

  pageSizeOptions?: number[];
}

export interface SortingConfig {
  state?: SortingState;
  initialState?: SortingState;
  onChange?: (sorting: SortingState) => void;
}

export interface DataTableProps<TData extends object> {
  data: TData[];
  columns: DataTableColumnDef<TData>[];
  selectable?: boolean;
  loading?: boolean;
  toolbar?: ReactNode;
  filters?: ReactNode;
  emptyState?: ReactNode;
  appearance?: Appearance;
  size?: TableSize;
  classNames?: TableClassNames;
  pagination?: PaginationConfig;
  sorting?: SortingConfig;
  rowSelection?: RowSelectionState;
  onRowSelectionChange?: (state: RowSelectionState) => void;
  onSelectedRowsChange?: (rows: TData[]) => void;
  getRowId?: (row: TData) => string;
}
