import { FiltersMap } from '@wix/bex-core';
import { useToolbarCollectionSyncProps } from '../ToolbarCollection/useToolbarCollectionSyncProps';
import { useColumnsSyncProps } from '../../hooks/useColumnsSyncProps';
import { TableFoldersProps } from './TableFolders';
import { useTagsBulkAssignFoldersUtils } from '../Tags/useTagsBulkAssignFoldersUtils';

export interface UseTableFoldersSyncPropsParams<
  T1,
  F1 extends FiltersMap,
  T2,
  F2 extends FiltersMap,
> extends TableFoldersProps<T1, F1, T2, F2> {}

export function useTableFoldersSyncProps<
  T1,
  F1 extends FiltersMap,
  T2,
  F2 extends FiltersMap,
>(props: UseTableFoldersSyncPropsParams<T1, F1, T2, F2>) {
  const { state, customColumns, columns } = props;

  const toolbar = state.toolbar;

  useToolbarCollectionSyncProps({
    ...props,
    state: toolbar,
    isUsingDragAndDrop: !!props.dragAndDrop,
    isUsingBulkActionsToolbar: !!props.bulkActionToolbar,
    isUsingHorizontalScroll: true,
    isUsingFolders: true,
    isUsingTableVirtualization: true,
  });

  useColumnsSyncProps({
    toolbar,
    customColumns,
    columns,
  });

  useTagsBulkAssignFoldersUtils({
    state,
  });

  return state;
}
