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

import HuAlert from '@material-hu/components/design-system/Alert';

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

import { type ScormTask, TaskStatus } from '../../types';
import { isTaskGraded } from '../../utils';

import ScormIframe from './ScormIframe';

type TaskScormProps = {
  task: ScormTask;
};

const TaskScorm = ({ task }: TaskScormProps) => {
  const { t } = useLokaliseTranslation('learning');

  if (!task || !task.url) return null;

  return (
    <Stack sx={{ gap: 2 }}>
      {isTaskGraded(task) && (
        <HuAlert
          title={t(`course.lesson.task_status.${task.status.toLowerCase()}`)}
          description={t('course.lesson.grade', { grade: task.grade })}
          severity={
            task.status === TaskStatus.FINISHED_OK ? 'success' : 'warning'
          }
        />
      )}
      <ScormIframe src={task.url} />
    </Stack>
  );
};

export default TaskScorm;
