import { useMutation } from 'react-query';

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

import { useLokaliseTranslation } from 'src/utils/i18n';

import { createCourseCategory } from '../services';
import { type CreateCourseCategoryParams } from '../types';

export const useCreateCourseCategory = () => {
  const { t } = useLokaliseTranslation('learning');
  const { enqueueSnackbar } = useSnackbar();

  return useMutation({
    mutationFn: (params: CreateCourseCategoryParams) =>
      createCourseCategory(params),
    onSuccess: () => {
      enqueueSnackbar({
        title: t('settings.categories.snackbar.create_success'),
        variant: 'success',
      });
    },
    onError: () => {
      enqueueSnackbar({
        title: t('settings.categories.snackbar.create_error'),
        variant: 'error',
      });
    },
  });
};
