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

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

import { CertificateInUseToastNeutral } from '../constants';
import {
  type CertificateActionType,
  type CertificateInUseToastAction,
} from '../types';

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

  const tAction = (
    action: CertificateActionType,
    suffix: string,
    args?: Record<string, unknown>,
  ) => t(`settings.certificates.actions.${action}.${suffix}`, args);

  return {
    success: (action: CertificateActionType, certificateName: string) =>
      enqueueSnackbar({
        title: tAction(action, 'success_title'),
        description: tAction(action, 'success_description', {
          certificateName,
        }),
        variant: 'success',
      }),

    error: (action: CertificateActionType) =>
      enqueueSnackbar({
        title: tAction(action, 'error_title'),
        description: t('general:retry_later'),
        variant: 'error',
      }),

    inUseError: (action: CertificateInUseToastAction) =>
      enqueueSnackbar({
        title:
          action === CertificateInUseToastNeutral
            ? t('settings.certificates.actions.in_use_neutral_toast_title')
            : tAction(action, 'in_use_toast_title'),
        variant: 'error',
      }),
  };
};
