import { LayoutActionsGroup, LayoutTableColumn, SerializedFunction } from 'src/models';

export interface W2WToolbarConfig {
  layoutCode: string;
  filters: FiltersConfig;
  columns?: ColumnsConfig;
  showToggleView?: boolean;
  title?: string;
  breadcrumbs?: any[];
  buttons?: ToolbarButton[];
  buttonGroups?: LayoutActionsGroup[];
  searchInput?: SearchInputConfig;
  states?: StateConfig;
  loading?: boolean;
}

export interface SearchInputConfig {
  show?: boolean;
  placeholder?: string;
  style?: string;
}

export interface FiltersConfig {
  items: FilterConfig[];
  persists?: boolean;
}
export interface FilterConfig {
  id?: string;
  code: string;
  type?: string;
  name: string;
  show?: boolean;
  initValue?: any;
  apply?: ApplyFilter;
  onChange?: SerializedFunction | Function;
  props?: {
    multiple?: boolean;
    clearable?: boolean;
    label?: string;
    options?: { label: string; value: any }[];
    [key: string]: any;
  };
}

export type ValueType = 'string' | 'number' | 'date' | 'boolean' | 'object';

export interface ToolbarButton {
  label: string;
  action: string;
  mode?: 'icon' | 'normal';
  icon?: string;
  iconRight?: string;
  show?: (props: any) => boolean | boolean;
}

export interface ComputedFilterConfig extends FilterConfig {
  component: string;
}

export interface ApplyFilter {
  key: string;
  strict: boolean; // false -> filter.bycol, true -> filter.byEqualCol
  custom?: boolean; // filter.custom
  format?: string; // | ((v: any) => any);
}

export interface ColumnsConfig {
  editable?: boolean;
  persists?: boolean;
  columns: LayoutTableColumn[];
}

export interface StateConfig {
  dynamic: boolean;
  items: StateItem[];
  visibility: SerializedFunction | null,
  queryUrl: string;
  filterToApply: SerializedFunction | null,
  loadUrl?: string
  useEstadosGama: boolean;
  counterType: 'estado' | 'perfil'
  url?: string
}

export interface StateItem {
  label: string;
  color: string;
  value: number | string;
  position?: number;
  state?: number | string // esto es para trabajar con counters que tengan el valor en este campo
}
