import { GridSortableContext } from './GridSortableContext';
import { GridDraggableCardItem } from './GridDraggableCardItem';
import { DraggableCardOverlay } from './DraggableCardOverlay';

import { CollectionDragAndDropState, DragAndDropState } from '../DragAndDrop';
import { FiltersMap } from '@wix/bex-core';
import { GridBaseState } from '../../state';

function setStateObject<T, F extends FiltersMap>({
  state,
  modalsContainerRef,
}: {
  state: GridBaseState<T, F>;
  modalsContainerRef: {
    current: HTMLElement | null | undefined;
  };
}) {
  state.collectionDragAndDropState ??= new CollectionDragAndDropState({
    state,
    a11yContainer: modalsContainerRef,
    container: state.container,
  });
  state.toolbar._dnd = state.collectionDragAndDropState.dnd as DragAndDropState<
    unknown,
    any
  >;
}

export const GridDragAndDrop = {
  SortableContext: GridSortableContext,
  DraggableCard: GridDraggableCardItem,
  DraggableCardOverlay,
  setStateObject,
};
