import React, { useContext } from 'react';
import { getNumericAttribute } from '../../dom-utils';
import { findScore, ResultsContext } from '../context/ResultsContext';
import ResultsExamQuestionManualScore from './internal/QuestionManualScore';
import { shortDisplayNumber } from '../../shortDisplayNumber';
import { QuestionContext } from '../context/QuestionContext';
import { useExamTranslation } from '../../i18n';
import classNames from 'classnames';
import AudioPlayer from '../shared/internal/AudioPlayer';
function AudioAnswer(audioAnswerProps) {
    var _a;
    const { element } = audioAnswerProps;
    const { answers } = useContext(QuestionContext);
    const { t, i18n } = useExamTranslation();
    const { answersByQuestionId, scores } = useContext(ResultsContext);
    const questionId = getNumericAttribute(element, 'question-id');
    const answer = answersByQuestionId[questionId];
    const value = answer && answer.value;
    const score = findScore(scores, questionId);
    const maxScore = getNumericAttribute(element, 'max-score');
    const displayNumber = answers.length > 1 ? shortDisplayNumber(element.getAttribute('display-number')) : undefined;
    const comment = (_a = score === null || score === void 0 ? void 0 : score.pregrading) === null || _a === void 0 ? void 0 : _a.comment;
    return (React.createElement(React.Fragment, null,
        React.createElement(ResultsExamQuestionManualScore, { scores: score, maxScore, displayNumber, questionId }),
        React.createElement("div", { className: classNames('audio-answer', {
                'no-answer': !value
            }), "aria-description": !value ? i18n.t('examineExam.questionHasNoAnswer') : undefined }, value ? (React.createElement(AudioPlayer, { src: value, variant: "recorded" })) : (React.createElement("span", { className: "e-normal" },
            " ",
            i18n.t('examineExam.questionHasNoAnswer')))),
        comment && (React.createElement(React.Fragment, null,
            React.createElement("h5", null, t('comment')),
            React.createElement("p", { className: "e-italic" }, comment)))));
}
export default React.memo(AudioAnswer);
//# sourceMappingURL=AudioAnswer.js.map