import classNames from 'classnames';
import React, { useContext } from 'react';
import { useExamTranslation } from '../../../i18n';
import { QuestionContext } from '../../context/QuestionContext';
import ResultsExamQuestionScoresContainer from './QuestionScoresContainer';
function QuestionManualScore({ scores, maxScore, displayNumber, multilineAnswer, questionId }) {
    var _a, _b, _c, _d, _e;
    const { answers } = useContext(QuestionContext);
    const containerProps = { answers, displayNumber, multilineAnswer, questionId };
    const shortCode = (_b = (_a = scores === null || scores === void 0 ? void 0 : scores.censoring) === null || _a === void 0 ? void 0 : _a.nonAnswerDetails) === null || _b === void 0 ? void 0 : _b.shortCode;
    return (React.createElement(ResultsExamQuestionScoresContainer, { ...containerProps }, ((_c = scores === null || scores === void 0 ? void 0 : scores.pregrading) === null || _c === void 0 ? void 0 : _c.score) == null && !((_e = (_d = scores === null || scores === void 0 ? void 0 : scores.censoring) === null || _d === void 0 ? void 0 : _d.scores) === null || _e === void 0 ? void 0 : _e.length) ? (React.createElement(NoPregrading, { maxScore })) : (React.createElement(React.Fragment, null,
        renderNormalizedScores(scores, maxScore),
        shortCode && React.createElement(NonAnswer, { shortCode: shortCode })))));
}
function renderNormalizedScores(scores, maxScore) {
    const normalizedScores = [
        scores.inspection && normalizeInspectionScore(scores.inspection),
        ...(scores.censoring ? normalizeCensoringScores(scores.censoring) : []),
        scores.pregrading && normalizePregradingScore(scores.pregrading)
    ].filter(Boolean);
    return normalizedScores.map((score, i) => React.createElement(ScoreRow, { key: i, ...score, latest: i === 0, maxScore: maxScore }));
}
function NoPregrading({ maxScore }) {
    const { t } = useExamTranslation();
    return (React.createElement(React.Fragment, null,
        React.createElement("span", { className: "e-result-scorecount-empty" }),
        maxScore && ` / ${maxScore} `,
        t('points', { count: '' })));
}
function NonAnswer({ shortCode }) {
    return (React.createElement("div", { className: "e-color-darkgrey e-columns e-columns--center-v" },
        React.createElement("span", { className: "e-font-size-xxxl e-light e-mrg-r-1" }, "\u00D7"),
        React.createElement("span", null, shortCode)));
}
function ScoreRow({ score, shortCode, type, maxScore, latest }) {
    const { t } = useExamTranslation();
    return (React.createElement("div", { className: latest ? 'e-color-black' : 'e-color-darkgrey e-font-size-xs' },
        React.createElement(ScoreColumn, { className: classNames('e-nowrap', { 'e-font-size-m': latest }) },
            latest ? React.createElement("b", null, score) : score,
            latest && maxScore ? ` / ${maxScore}` : '',
            ` p.`),
        React.createElement(ScoreColumn, { className: "e-result-scorecount-shortcode" }, shortCode),
        React.createElement(ScoreColumn, { className: "e-mrg-r-0" }, t(type))));
}
function ScoreColumn({ className, children }) {
    return React.createElement("span", { className: classNames('e-mrg-r-1 e-nowrap', className) }, children);
}
function normalizePregradingScore({ score }) {
    return score !== undefined ? { score, shortCode: '', type: 'grading.pregrading-abbrev' } : null;
}
function normalizeCensoringScores(score) {
    return score.scores.map((s, i) => ({
        score: s.score,
        shortCode: s.shortCode || '',
        type: `grading.round.${score.scores.length - i}`
    }));
}
function normalizeInspectionScore(score) {
    return {
        score: score.score,
        shortCode: score.shortCodes ? score.shortCodes.join(', ') : '',
        type: 'grading.inspection-grading-abbrev'
    };
}
export default React.memo(QuestionManualScore);
//# sourceMappingURL=QuestionManualScore.js.map