import { useRef } from 'react';
import { Helmet } from 'react-helmet-async';

import Stack from '@material-hu/mui/Stack';

import HuTitle from '@material-hu/components/design-system/Title';

import useHuGoTheme from 'src/hooks/useHuGoTheme';
import { formatTitle } from 'src/utils/helmetUtils';
import { useLokaliseTranslation } from 'src/utils/i18n';

import { TemplatesList } from './components';

const SurveyTemplates = () => {
  const HuGoThemeProvider = useHuGoTheme();
  const pageRef = useRef<HTMLDivElement>(null);
  const { t } = useLokaliseTranslation('people_experience');

  const pageTitle = t('templates');

  const handleScrollToTop = () => {
    pageRef.current?.scrollTo({ top: 0, behavior: 'smooth' });
  };

  return (
    <>
      <Helmet>
        <title>{formatTitle(pageTitle)}</title>
      </Helmet>
      <HuGoThemeProvider>
        <Stack
          sx={{
            gap: 4,
            py: 8,
            px: 12,
            backgroundColor: theme =>
              theme.palette.new.background.layout.default,
            height: '100%',
            overflowY: 'auto',
          }}
          ref={pageRef}
        >
          <HuTitle
            variant="L"
            title={t('survey.quick_launch.title')}
            description={t('survey.quick_launch.description')}
            withEllipsis
          />
          <TemplatesList onScrollToTop={handleScrollToTop} />
        </Stack>
      </HuGoThemeProvider>
    </>
  );
};

export default SurveyTemplates;
