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

import PdfFullScreen from '@material-hu/components/composed-components/PdfViewer/components/FullScreen';
import Button from '@material-hu/components/design-system/Buttons/Button';

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

import useCertificate from '../../hooks/useCertificate';
import { type Path } from '../../types';

export type PathCertificateProps = {
  path: Path;
};

const PathCertificate = ({ path }: PathCertificateProps) => {
  const { t } = useLokaliseTranslation('learning');

  const { file, open, close, isLoading } = useCertificate(path);

  return (
    <Stack sx={{ mt: 2 }}>
      {file && (
        <PdfFullScreen
          name={file.name}
          file={file.url || ''}
          onClose={close}
        />
      )}
      <Button
        variant="primary"
        onClick={open}
        startIcon={<IconCertificate />}
        loading={isLoading}
      >
        {t('common.view_certificate')}
      </Button>
    </Stack>
  );
};

export default PathCertificate;
