import { useNavigate } from 'react-router-dom';

import { IconCircleX, IconWifiOff } from '@material-hu/icons/tabler';
import { cardContentClasses } from '@material-hu/mui/CardContent';
import Stack from '@material-hu/mui/Stack';
import { useTheme } from '@material-hu/mui/styles';

import HuAvatar from '@material-hu/components/design-system/Avatar';
import Button from '@material-hu/components/design-system/Buttons/Button';
import HuCardContainer from '@material-hu/components/design-system/CardContainer';
import HuTitle from '@material-hu/components/design-system/Title';

import { ErrorType } from '../../types';
import { useLokaliseTranslation } from 'src/utils/i18n';

import { pxRoutes } from '../../routes';

type ErrorMessageProps = {
  type: ErrorType;
};

const ErrorMessage = ({ type }: ErrorMessageProps) => {
  const { t } = useLokaliseTranslation('people_experience');
  const theme = useTheme();
  const navigate = useNavigate();

  const ERROR_META = {
    [ErrorType.Access]: {
      title: t('ACCESS_ERROR_TITLE'),
      description: t('ACCESS_ERROR_DESCRIPTION'),
      icon: IconCircleX,
    },
    [ErrorType.Connection]: {
      title: t('CONNECTION_ERROR_TITLE'),
      description: t('CONNECTION_ERROR_DESCRIPTION'),
      icon: IconWifiOff,
    },
    [ErrorType.RespondSurvey]: {
      title: t('RESPOND_ERROR_TITLE'),
      description: t('RESPOND_ERROR_DESCRIPTION'),
      icon: IconCircleX,
    },
  };

  const handleClose = () => {
    navigate(pxRoutes.collaboratorSurveysBase());
  };

  return (
    <Stack
      sx={{
        bgcolor: theme.palette.new.background.layout.default,
        height: '100%',
        pt: 9,
        alignItems: 'center',
      }}
    >
      <HuCardContainer
        padding={24}
        sx={{
          maxWidth: 864,
          px: 4,
          [`.${cardContentClasses.root}`]: {
            display: 'flex',
            flexDirection: 'column',
            alignItems: 'center',
          },
        }}
        fullWidth
      >
        <HuAvatar
          Icon={ERROR_META[type].icon}
          color="error"
          size="large"
        />
        <HuTitle
          variant="L"
          title={ERROR_META[type].title}
          description={ERROR_META[type].description}
          sx={{
            mt: 1.5,
          }}
          centered
        />
        <Button
          variant="secondary"
          onClick={handleClose}
          sx={{
            mt: 3,
          }}
        >
          {t('CLOSE_AND_TRY_AGAIN')}
        </Button>
      </HuCardContainer>
    </Stack>
  );
};

export default ErrorMessage;
