import { FiltersMap } from '@wix/bex-core';
import { NestedCollectionLevelDescriptor } from './NestedCollectionLevelDescriptor';
import { ActionCell } from '../../components/ActionCell';
import {
  NestedTableNestColumns,
  RenderMainColumn,
} from './NestedTableNodeState';
import { NestedDragEndEvent } from '../../components/NestedTableDragAndDrop/NestedTableDragAndDropState';
import { DragAndDropCancelResult } from '../../components/DragAndDrop/DragAndDrop';

export interface NestedTableLevelDescriptor<
  C extends string,
  T,
  F extends FiltersMap,
> extends NestedCollectionLevelDescriptor<T, F> {
  /**
   * Render logic of the cells for this level. By default, all cells will be empty
   */
  readonly columns?: NestedTableNestColumns<C, T>;
  /**
   * Render logic of the main column for this level.
   * @overrideType (item: T) => { title?: string; subtitle?: string; image?: ReactNode; }
   */
  readonly renderMainColumn?: RenderMainColumn<T>;
  /**
   * A table's last column. Use this column to add an action at the end of each row. For example, a delete button to delete an item. Pass an [`ActionCellProps`](https://www.docs.wixdesignsystem.com/?path=/story/components-lists-table--tableactioncell) object, or a function that returns an `ActionCellProps` object.
   */
  readonly actionCell?: ActionCell<T, F>;
  /**
   * A function that accepts the item of the current level and returns an array of breadcrumbs to be displayed in the toolbar. Each breadcrumb is an object with `id` and `name` properties. `fetchData` will be called with `query.fields` that contains the value `breadcrumbs` to signal that the breadcrumbs should be fetched.
   */
  readonly breadcrumbs?: (
    item: T,
  ) => { id: string; name: string }[] | null | undefined;
  /**
   * A function that accepts the item of the current level and returns a boolean value that indicates whether the item can be expanded. By default, all items are expandable.
   */
  readonly expandable?: (item: T) => boolean;
  /**
   * A function that accepts the item of the current level and returns a boolean value indicating whether the item should be highlighted.
   */
  readonly isRowHighlight?: (item: T) => boolean;
  readonly onAddNewClick?: () => void;
  readonly dragAndDropSubmit?: (
    event: NestedDragEndEvent<C, T, F>,
  ) => Promise<void>;
  readonly dragAndDropCancel?: (
    event: NestedDragEndEvent<C, T, F>,
  ) => DragAndDropCancelResult | Promise<DragAndDropCancelResult>;

  readonly dragAndDropDisabled?: (
    params: NestedDragEndEvent<C, T, F>,
  ) => { errorMessage: string } | null | undefined;
}
