import { FiltersMap } from '@wix/bex-core';
import { observer } from 'mobx-react-lite';
import { ToolbarCollectionState } from '../../state';
import { MultiCollectionBulkActionToolbarRenderProps } from './MultiCollectionBulkActionRenderProps';

export interface MultiCollectionBulkActionToolbarProps<
  T,
  F extends FiltersMap,
> {
  state: ToolbarCollectionState<T, F>;
  bulkActionToolbar: MultiCollectionBulkActionToolbarRenderProps;
}

function _MultiCollectionBulkActionToolbar<T, F extends FiltersMap>(
  props: MultiCollectionBulkActionToolbarProps<T, F>,
) {
  const { state, bulkActionToolbar } = props;
  const { bulk } = state;

  const {
    allSelected,
    clearSelection,
    modals: { openModal, closeModal, openConfirmModal, isModalOpen },
  } = bulk;

  return bulkActionToolbar({
    isModalOpen,
    allSelected,
    openModal,
    closeModal,
    openConfirmModal,
    clearSelection,
  });
}

export const MultiCollectionBulkActionToolbar = observer(
  _MultiCollectionBulkActionToolbar,
);
