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

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

import Button from '@material-hu/components/design-system/Buttons/Button';

import { useLokaliseTranslation } from 'src/utils/i18n';
import { LogEvents, logEvent } from 'src/utils/logging';

import useSessionsTitle from '../../hooks/useSessionsTitle';
import { sessionsRoutes } from '../../routes';

const SessionsHeader = () => {
  const { t } = useLokaliseTranslation('learning');
  const title = useSessionsTitle();
  const navigate = useNavigate();

  const handleCreateSession = () => {
    navigate(sessionsRoutes.new());
    logEvent(LogEvents.NEW_SESSION_INICIATED);
  };

  return (
    <Stack
      sx={{
        justifyContent: 'space-between',
        alignItems: 'center',
        flexDirection: 'row',
      }}
    >
      <Typography
        variant="globalL"
        fontWeight="fontWeightSemiBold"
      >
        {title}
      </Typography>
      <Button
        variant="primary"
        startIcon={<IconPlus />}
        onClick={handleCreateSession}
      >
        {t('session.create')}
      </Button>
    </Stack>
  );
};

export default SessionsHeader;
