import type { TemplateResult } from '@design.estate/dees-element';
import type { TIconKey } from '../dees-icon/dees-icon.js';

export interface ITableActionDataArg<T> {
  item: T;
  table: any; // avoid circular typing with DeesTable; consumers rely on shape only
}

export interface ITableAction<T = any> {
  name: string;
  iconName: TIconKey;
  useTableBehaviour?: 'upload' | 'cancelUpload' | 'none';
  type: ('inRow' | 'contextmenu' | 'doubleClick' | 'footer' | 'header' | 'preview' | 'keyCombination')[];
  actionRelevancyCheckFunc?: (itemArg: T) => boolean;
  actionFunc: (actionDataArg: ITableActionDataArg<T>) => Promise<any>;
}

export interface Column<T = any> {
  key: keyof T | string;
  header?: string | TemplateResult;
  value?: (row: T) => any;
  renderer?: (value: any, row: T, ctx: { rowIndex: number; colIndex: number; column: Column<T> }) => TemplateResult | string;
  sortable?: boolean;
  /** whether this column participates in per-column quick filtering (default: true) */
  filterable?: boolean;
  hidden?: boolean;
}

export type TDisplayFunction<T = any> = (itemArg: T) => Record<string, any>;
