import { useMutation } from 'react-query';

import useSnackbar from '@material-hu/components/design-system/Snackbar';

import { deleteShiftTemplate } from 'src/services/shifts';
import { useLokaliseTranslation } from 'src/utils/i18n';

import { invalidateShiftsRepository } from '../queries';

export const useDeleteShiftTemplateMutation = () => {
  const { t } = useLokaliseTranslation('shifts');
  const { enqueueSnackbar } = useSnackbar();

  return useMutation({
    mutationFn: deleteShiftTemplate,
    onSuccess: async () => {
      await invalidateShiftsRepository(false);
    },
    onError: () => {
      enqueueSnackbar({
        title: t('actions.delete_shift.error'),
        description: t('actions.try_again'),
        variant: 'error',
      });
    },
  });
};
