import React, { useContext, useLayoutEffect, useRef } from 'react';
import { useExamTranslation } from '../../i18n';
import { renderAnnotations } from '../../renderAnnotations';
import { ScreenReaderOnly } from '../ScreenReaderOnly';
import classNames from 'classnames';
import { updateLargeImageWarnings } from '../grading/largeImageDetector';
import { wrapAllImages } from '../../dom-utils';
import { ResultsContext } from '../context/ResultsContext';
export const MultiLineAnswer = ({ type, score, value }) => {
    const { t, i18n } = useExamTranslation();
    const { showAnnotationsAndZoomImages = true } = useContext(ResultsContext);
    const answerRef = useRef(null);
    useLayoutEffect(() => {
        var _a, _b, _c, _d;
        if (answerRef.current) {
            answerRef.current.innerHTML = value || '';
            if (showAnnotationsAndZoomImages) {
                wrapAllImages(answerRef.current);
                updateLargeImageWarnings(answerRef.current);
                renderAnnotations(answerRef.current, (_b = (_a = score === null || score === void 0 ? void 0 : score.pregrading) === null || _a === void 0 ? void 0 : _a.annotations) !== null && _b !== void 0 ? _b : [], (_d = (_c = score === null || score === void 0 ? void 0 : score.censoring) === null || _c === void 0 ? void 0 : _c.annotations) !== null && _d !== void 0 ? _d : []);
            }
        }
    }, [value, score, showAnnotationsAndZoomImages]);
    return (React.createElement("div", { className: classNames('e-multiline-results-text-answer e-line-height-l e-pad-x-2 e-mrg-b-1', {
            'no-answer': !value
        }), "aria-description": !value ? i18n.t('examineExam.questionHasNoAnswer') : undefined },
        React.createElement(ScreenReaderOnly, null, t('screen-reader.answer-begin')),
        type === 'rich-text' ? (React.createElement("div", { dangerouslySetInnerHTML: { __html: value || '' }, ref: answerRef })) : (React.createElement("div", { className: "e-pre-wrap", ref: answerRef }, value)),
        React.createElement(ScreenReaderOnly, null, t('screen-reader.answer-end'))));
};
//# sourceMappingURL=MultiLineAnswer.js.map