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

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

import useStartPath from '../../hooks/useStartPath';
import { type Path, PathStatus } from '../../types';
import { showCertificate } from '../../utils';

export type PathStartButtonProps = {
  path: Path;
};

const PathStartButton = ({ path }: PathStartButtonProps) => {
  const { t } = useLokaliseTranslation('learning');
  const { startPath } = useStartPath(path);

  const variant = showCertificate(path) ? 'secondary' : 'primary';

  const label = {
    [PathStatus.ALL]: t('general:actions.start'),
    [PathStatus.PENDING]: t('general:actions.start'),
    [PathStatus.IN_PROGRESS]: t('general:continue'),
    [PathStatus.FINISHED]: t('path.view'),
  }[path.status];

  const handleClick = () => startPath();

  return (
    <Button
      variant={variant}
      onClick={handleClick}
    >
      {label}
    </Button>
  );
};

export default PathStartButton;
