import React from 'react';
import { findChildElement, getNumericAttribute, parentElements, queryAll } from '../../dom-utils';
import { withContext } from './withContext';
import { questionInstructionId, questionTitleId } from '../../ids';
export const QuestionContext = React.createContext({});
export const withQuestionContext = withContext(QuestionContext, ({ element }) => {
    const childQuestions = queryAll(element, 'question', false);
    const answers = childQuestions.length
        ? []
        : queryAll(element, ['text-answer', 'scored-text-answer', 'dropdown-answer', 'choice-answer', 'dnd-answer', 'audio-answer'], false);
    const questionInstructions = queryAll(element, 'question-instruction', false);
    const displayNumber = element.getAttribute('display-number');
    const questionLabelIds = questionInstructions.length > 0
        ? questionInstructions.map(questionInstructionId).join(' ')
        : questionTitleId(displayNumber);
    return {
        answers,
        displayNumber,
        hasExternalMaterial: findChildElement(element, 'external-material') != null,
        maxAnswers: getNumericAttribute(element, 'max-answers'),
        maxScore: getNumericAttribute(element, 'max-score'),
        level: parentElements(element, 'question').length,
        childQuestions,
        questionLabelIds
    };
});
//# sourceMappingURL=QuestionContext.js.map