import React, { useContext } from 'react';
import { getNumericAttribute } from '../../dom-utils';
import { useExamTranslation } from '../../i18n';
import { shortDisplayNumber } from '../../shortDisplayNumber';
import AnswerToolbar from '../AnswerToolbar';
import { QuestionContext } from '../context/QuestionContext';
import { findScore, ResultsContext } from '../context/ResultsContext';
import AnswerLengthInfo from '../shared/AnswerLengthInfo';
import ResultsExamQuestionManualScore from './internal/QuestionManualScore';
import { MultiLineAnswer } from './MultiLineAnswer';
import ResultsSingleLineAnswer from './SingleLineAnswer';
function TextAnswer({ element }) {
    var _a;
    const { answers } = useContext(QuestionContext);
    const { answersByQuestionId, scores } = useContext(ResultsContext);
    const { t } = useExamTranslation();
    const questionId = getNumericAttribute(element, 'question-id');
    const maxScore = getNumericAttribute(element, 'max-score');
    const answer = answersByQuestionId[questionId];
    const value = answer && answer.value;
    const displayNumber = answers.length > 1 ? shortDisplayNumber(element.getAttribute('display-number')) : undefined;
    const score = findScore(scores, questionId);
    const comment = (_a = score === null || score === void 0 ? void 0 : score.pregrading) === null || _a === void 0 ? void 0 : _a.comment;
    const type = (element.getAttribute('type') || 'single-line');
    const maxLength = getNumericAttribute(element, 'max-length');
    switch (type) {
        case 'rich-text': {
            return (React.createElement(React.Fragment, null,
                maxLength != null && React.createElement(AnswerLengthInfo, { maxLength }),
                React.createElement(ResultsExamQuestionManualScore, { multilineAnswer: true, scores: score, maxScore: maxScore, questionId: questionId }),
                React.createElement(MultiLineAnswer, { type, value, score }),
                React.createElement(AnswerToolbar, { answer,
                    element }),
                comment && (React.createElement(React.Fragment, null,
                    React.createElement("h5", null, t('comment')),
                    React.createElement("p", { className: "e-italic" }, comment)))));
        }
        case 'single-line':
        default:
            return (React.createElement(ResultsSingleLineAnswer, { answers,
                score,
                displayNumber,
                value },
                React.createElement(ResultsExamQuestionManualScore, { scores: score, maxScore, displayNumber, questionId })));
    }
}
export default React.memo(TextAnswer);
//# sourceMappingURL=TextAnswer.js.map