import { InputOption, InputType } from './form.model';
import { Sort, SortFunction } from './sort.model';

export enum ColumnType {
  Boolean = 'Boolean',
  Date = 'Date',
  String = 'String',
}

export interface TableHeader {
  label: string;
  key: string;
  align?: 'start' | 'center' | 'end';
  class?: string;
  width?: string;
  sortable?: boolean;
  sortFunction?: SortFunction;
  action?: boolean;
  columnType?: ColumnType;
  helperText?: string;
}

export interface ServerTableRequestParams {
  size: number;
  offset: number;
  page: number;
  search: string;
  filters?: Filter[];
  sort?: Sort;
}

export type FilterType =
  | 'select'
  | 'input'
  | 'inputDate'
  | 'boolean'
  | 'autocomplete'
  | 'autocompleteServer'
  | 'betweenNumber'
  | 'betweenDate'
  | 'betweenDateTime';

export interface Filter {
  label: string;
  inputType?: InputType;
  key: string;
  type: FilterType;
  value?: any;
  valueFrom?: any;
  valueTo?: any;
  selectOptions?: { label: string; value: any }[];
  autocompleteOptions?: string[] | { label: string; value: string }[];
  autocompleteRequest?: (
    abortController: AbortController,
    url?: string,
  ) => Promise<{ data: InputOption[] }>;
  customFilter?: Function;
  multiple?: boolean;
  selectAll?: boolean;
  selectAllLabel?: string;
}

export interface SavedFilter {
  id: string;
  name: string;
  icon?: string;
  unDeletable?: boolean;
  route: string;
  filters: { target: string; value: any }[];
}

export enum SelectMode {
  ALL = 'all',
  DEFAULT = 'default',
  SINGLE = 'single',
}

export enum TableMode {
  NORMAL = 'normal',
  DENSE = 'dense',
  SMALL = 'small',
}
