import React, { useState, useEffect } from 'react';
import { Container, Row, Col, ListGroup, Button, Modal, Alert, OverlayTrigger, Popover } from 'react-bootstrap';
import { useNavigate, useParams } from 'react-router-dom';
import useExercises from '../hooks/useExercises';
import ilustration from '../../../../assets/images/illustration/submitExercise.png';
import Skeleton from 'react-loading-skeleton';
import MatchingPairs from './components/MatchingPair';
const Exercise = () => {
const [showModal, setShowModal] = useState(false);
const [showAlert, setShowAlert] = useState(false);
const [activeIndex, setActiveIndex] = useState(null);
const { section, topic, level } = useParams();
const navigate = useNavigate();
const {
questions,
loading,
error,
answers,
currentQuestion,
popover,
setAnswers,
setCurrentQuestion,
handleAnswerSelect,
handleNextQuestion,
handlePrevQuestion,
handleSubmit,
getCurrentQuestionData,
handleConfirmSubmit
} = useExercises( topic, level );
const handleSubmitWrapper = () => {
if (handleSubmit()) {
setShowModal(true);
} else {
setShowAlert(true);
}
};
// const handleConfirmSubmit = () => {
// setShowModal(false);
// navigate(`/learning/module/${section}/${topic}/${level}/result`, {
// state: { answers }
// });
// };
const handleCloseModal = () => setShowModal(false);
const currentQuestionData = getCurrentQuestionData();
const questionId = currentQuestionData.id || '';
const handleSelectLeft = (index) => {
setActiveIndex(index);
};
if (loading) {
return (
);
}
return (
Pretest
{questions.map((q, index) => (
setCurrentQuestion(index)}
className={`border-0 rounded-3 number-label ${answers[index] !== null ? 'answered fw-bold' : ''}`}
style={{ cursor: 'pointer' }}
>
{index+1}
))}
{`Questions ${currentQuestion + 1} of ${questions.length}`}
{currentQuestionData.image && (
)}
{currentQuestionData.IMAGE !== null && (
{/*

*/}
{currentQuestionData.IMAGE}
)}
{currentQuestionData.AUDIO !== null && (
{/*
*/}
{/*
*/}
{currentQuestionData.AUDIO}
)}
{currentQuestionData.VIDEO !== null && (
//
{currentQuestionData.VIDEO}
)}
{currentQuestionData.QUESTION}
{currentQuestionData.QUESTION_TYPE === "MCQ" && (
{/* {currentQuestionData.options?.map((option, idx) => (
handleAnswerSelect(idx)}
>
{String.fromCharCode(65 + idx)}
{option}
))} */}
handleAnswerSelect(0)}
>
A
{currentQuestionData.multipleChoices[0].OPTION_A}
handleAnswerSelect(1)}
>
B
{currentQuestionData.multipleChoices[0].OPTION_B}
handleAnswerSelect(2)}
>
C
{currentQuestionData.multipleChoices[0].OPTION_C}
handleAnswerSelect(3)}
>
D
{currentQuestionData.multipleChoices[0].OPTION_D}
{currentQuestionData.multipleChoices[0].OPTION_E && (
handleAnswerSelect(4)}
>
E
{currentQuestionData.multipleChoices[0].OPTION_E}
)}
)}
{currentQuestionData.QUESTION_TYPE === "TFQ" && (
handleAnswerSelect(0)}
>
A
TRUE
handleAnswerSelect(1)}
>
B
FALSE
)}
{currentQuestionData.QUESTION_TYPE === "MPQ" &&(
//
//
// {currentQuestionData.matchingPairs?.map((option, idx) => (
//
handleLeftChoose(idx)}
// >
// {idx + 1}
// {/* {idx + 1} */}
// {/* {option.LEFT_PAIR} */}
// {option.LEFT_PAIR}
//
// ))}
//
//
// {currentQuestionData.matchingPairs?.map((option, idx) => (
//
handleRightChoose(idx)}
// >
// {idx + 1}
// {/* {idx + 1} */}
// {/* {option.LEFT_PAIR} */}
// {option.RIGHT_PAIR}
//
// ))}
//
//
)}
setShowAlert(false)} dismissible>
ATTENTION!
Please answer all questions before submitting.
{/*
Confirmation
Are you sure you want to submit your answer?
*/}
Proceed with Submission?
Confirm submission? There's no going back.
);
};
export default Exercise;