import { type FC } from 'react';

import { IconCircleX } from '@material-hu/icons/tabler';
import Button from '@material-hu/mui/Button';
import Stack from '@material-hu/mui/Stack';
import Typography from '@material-hu/mui/Typography';

import HuAvatar from '@material-hu/components/design-system/Avatar';

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

type MediaErrorProps = {
  onRetry: () => void;
  amountOfErrors: number;
  onClose: () => void;
};

const MediaError: FC<MediaErrorProps> = ({
  onRetry,
  amountOfErrors,
  onClose,
}) => {
  const { t } = useLokaliseTranslation(['chat']);
  const generalErrorKey =
    amountOfErrors === 1 ? 'chat:errors.load_media' : 'chat:errors.load_medias';
  return (
    <Stack
      sx={{
        alignItems: 'center',
        justifyContent: 'center',
        gap: 2,
      }}
    >
      <HuAvatar
        Icon={IconCircleX}
        color="error"
      />
      <Stack sx={{ alignItems: 'center' }}>
        <Typography
          variant="globalM"
          fontWeight="fontWeightSemiBold"
        >
          {t(generalErrorKey)}
        </Typography>
      </Stack>
      <Stack sx={{ alignItems: 'center', gap: 0.5, flexDirection: 'row' }}>
        {amountOfErrors > 1 && (
          <Button
            variant="outlined"
            onClick={onClose}
          >
            {t('chat:groups.go_back_chat')}
          </Button>
        )}
        <Button
          variant="outlined"
          onClick={onRetry}
        >
          {t('try_again')}
        </Button>
      </Stack>
    </Stack>
  );
};

export default MediaError;
