import React from 'react';
import { getAttribute, getNumericAttribute, queryAll } from '../../dom-utils';
import { withContext } from './withContext';
export const CommonExamContext = React.createContext({});
export function withCommonExamContext(Component) {
    return withContext(CommonExamContext, ({ attachmentsURL, resolveAttachment, doc, abitti2 }) => {
        var _a;
        const root = doc.documentElement;
        const maybeDate = getAttribute(root, 'date');
        const language = getAttribute(root, 'exam-lang');
        const examType = (_a = getAttribute(root, 'exam-type')) !== null && _a !== void 0 ? _a : 'normal';
        const subjectLanguage = getAttribute(root, 'lang') || language;
        return {
            attachmentsURL,
            date: maybeDate ? new Date(maybeDate) : undefined,
            dateTimeFormatter: new Intl.DateTimeFormat('fi-FI', { timeZone: 'UTC' }),
            dayCode: getAttribute(root, 'day-code'),
            examCode: getAttribute(root, 'exam-code'),
            language,
            subjectLanguage,
            examType,
            maxAnswers: getNumericAttribute(root, 'max-answers'),
            maxScore: getNumericAttribute(root, 'max-score'),
            sections: queryAll(root, 'section'),
            resolveAttachment,
            abitti2: abitti2 || false,
            root
        };
    })(Component);
}
//# sourceMappingURL=CommonExamContext.js.map