import { TableDragAndDrop as WSRTableDragAndDrop } from '@wix/wix-style-react-incubator/drag-and-drop';
import { NestedTableDragAndDropContext } from './NestedTableDragAndDropContext';
import { NestedTableDragAndDropState } from './NestedTableDragAndDropState';
import { minimalRequiredWdsRuntimeCheck } from '../../minimalRequiredWdsRuntimeCheck';
import { NestedTableState } from '../../state/NestedTableState';
import { NestedTableDragHandle } from './NestedTableDragHandle';
import { NestedTableGhostIndentationCell } from './NestedTableGhostIndentationCell';
import { NestedTableDragAndDropRow } from './NestedTableDragAndDropRow';

if (process.env.NODE_ENV !== 'production') {
  minimalRequiredWdsRuntimeCheck({
    required: '^1.64.1',
    requiredBy: 'WixPatterns/NestedTableDragAndDrop',
  });
}
function setStateObject<C extends string>(params: {
  state: NestedTableState<C>;
}) {
  const { state } = params;
  state.nested.nestedTableDragAndDrop ??= new NestedTableDragAndDropState({
    nestedState: state.nested,
  });
  state.tableState.tableDragAndDropState = state.nested.nestedTableDragAndDrop;
  state.toolbar._dnd = state.nested.nestedTableDragAndDrop.dnd;
}

export const NestedTableDragAndDrop = {
  ...WSRTableDragAndDrop,
  createDragHandleColumn: null, // override default TableDragAndDrop.createDragHandleColumn - in NestedTable the drag handle is rendered manually in `<NestedTableParentCell/>`
  NestedTableDragAndDropContext,
  NestedTableDragAndDropRow,
  setStateObject,
  NestedTableDragHandle,
  NestedTableGhostIndentationCell,
};
