import { useDispatch, useSelector } from 'react-redux';

import {
  CANCEL_ALL_UPLOAD_TEXT_BODY,
  CANCEL_ALL_UPLOAD_TEXT_CANCEL_BUTTON,
  CANCEL_ALL_UPLOAD_TEXT_CONFIRM_BUTTON,
  CANCEL_ALL_UPLOAD_TEXT_TITLE,
} from '@/modules/uploaderNew/constants';

import { getFilesProcessingStatuses } from '@/modules/uploaderNew/components/MultiUploadStatusDialog/helpers';
import { queueSelector } from '@/modules/uploaderNew/redux/selectors';
import { showCancelUploadConfirmDialogAction } from '@/modules/uploaderNew/redux/slices';

function useShowCancelUploadDialog() {
  const dispatch = useDispatch();
  const q = useSelector(queueSelector);
  const { hasInProgress } = getFilesProcessingStatuses(q);
  const handleOpenConfirmDialog = (context) => {
    dispatch(
      showCancelUploadConfirmDialogAction({
        title: CANCEL_ALL_UPLOAD_TEXT_TITLE,
        body: CANCEL_ALL_UPLOAD_TEXT_BODY,
        cancelButtonText: CANCEL_ALL_UPLOAD_TEXT_CANCEL_BUTTON,
        confirmButtonText: CANCEL_ALL_UPLOAD_TEXT_CONFIRM_BUTTON,
        context,
      }),
    );
  };

  return {
    hasInProgress,
    handleOpenConfirmDialog,
  };
}

export default useShowCancelUploadDialog;
