export type DataTableRecord = Record<string, unknown> & {
  readonly id?: string | number;
  readonly status?: unknown;
  readonly isActive?: boolean;
};  /* table row is an object with string keys */

export type DataTableActionType = 'view' | 'edit' | 'delete' | string;

export interface DataTableColumn<T extends DataTableRecord = DataTableRecord> {
  key: Extract<keyof T, string> | string;
  label: string;
  header: string;
  sortable?: boolean;
  width?: string;
  align?: 'left' | 'center' | 'right';
  headerAlign?: 'left' | 'center' | 'right';
  formatter?: (value: unknown, row: T) => string | number; /* for change the value of custom cell like date format */
  badge?: boolean;
  badgeClass?: (value: unknown, row: T) => string; /* this is to show the badge according to status of record */

  headerClass?: string;
  cellClass?: string;
}

export interface DataTableAction<T extends DataTableRecord = DataTableRecord> {
  type: DataTableActionType;
  label: string;
  icon?: string;
  className?: string;
  tooltip?: string;
  permission?: string;
  disabled?: (row: T) => boolean;
  visible?: (row: T) => boolean;
}

export interface DataTablePageEvent {
  pageIndex: number;
  pageSize: number;
}

export interface DataTableSortEvent {
  column: string;
  direction: 'asc' | 'desc';
}

export interface DataTableActionEvent<T extends DataTableRecord = DataTableRecord> {
  action: DataTableAction<T>;
  row: T;
}

/* for custom cell templates */
export interface DataTableCellContext<T extends DataTableRecord = DataTableRecord> {
  $implicit: T;
  row: T;
  value: unknown;
}

export interface DataTableQuery {
  draw: number;
  page: number;
  pageSize: number;
  sortBy?: string | null;
  sortDir: 'asc' | 'desc';
  search?: string | null;
  isActive?: boolean | null;
}

export interface DataTableResult<T> {
  draw: number;
  total: number;
  filtered: number;
  rows: T[];
}
