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

export interface MultiCollectionBulkActionModalProps<T, F extends FiltersMap> {
  state: ToolbarCollectionState<T, F>;
  bulkActionModal: MultiCollectionBulkActionModalRenderProps;
}

function _MultiCollectionBulkActionModal<T, F extends FiltersMap>(
  props: MultiCollectionBulkActionModalProps<T, F>,
) {
  const { state, bulkActionModal } = props;
  const { bulk } = state;

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

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

export const MultiCollectionBulkActionModal = observer(
  _MultiCollectionBulkActionModal,
);
