import React, { useContext } from 'react';
import { getNumericAttribute } from '../../dom-utils';
import { shortDisplayNumber } from '../../shortDisplayNumber';
import { QuestionContext } from '../context/QuestionContext';
import { findScore, ResultsContext } from '../context/ResultsContext';
import ResultsExamQuestionAutoScore from './internal/QuestionAutoScore';
import ResultsSingleLineAnswer from './SingleLineAnswer';
function ScoredTextAnswer({ element }) {
    const { answers } = useContext(QuestionContext);
    const { answersByQuestionId, scores } = useContext(ResultsContext);
    const questionId = getNumericAttribute(element, 'question-id');
    const maxScore = getNumericAttribute(element, 'max-score');
    const answer = answersByQuestionId[questionId];
    const value = answer && answer.value;
    const displayNumber = shortDisplayNumber(element.getAttribute('display-number'));
    const score = findScore(scores, questionId);
    const autogradingScore = score === null || score === void 0 ? void 0 : score.autograding;
    return (React.createElement(ResultsSingleLineAnswer, { answers: answers, displayNumber: displayNumber, value: value, score: score },
        React.createElement(ResultsExamQuestionAutoScore, { score: autogradingScore === null || autogradingScore === void 0 ? void 0 : autogradingScore.score, maxScore: maxScore, displayNumber: answers.length > 1 ? displayNumber : undefined, questionId: questionId })));
}
export default React.memo(ScoredTextAnswer);
//# sourceMappingURL=ScoredTextAnswer.js.map