import { getAttribute, getNumericAttribute, queryAll } from '../dom-utils';
export function parseExamStructure(doc) {
    const root = doc.documentElement;
    const sections = queryAll(root, 'section', false).map(parseSection);
    return parseElement(root, sections, { maxAnswers: getNumericAttribute(root, 'max-answers') });
}
function parseSection(section) {
    const questions = queryAll(section, 'question', false).map(parseQuestion);
    return parseElement(section, questions, {
        displayNumber: getAttribute(section, 'display-number'),
        minAnswers: getNumericAttribute(section, 'min-answers'),
        maxAnswers: getNumericAttribute(section, 'max-answers')
    });
}
function parseQuestion(question) {
    const childQuestions = queryAll(question, 'question', false);
    const childElements = childQuestions.length
        ? childQuestions.map(parseQuestion)
        : queryAll(question, ['text-answer', 'scored-text-answer', 'choice-answer', 'dropdown-answer', 'dnd-answer', 'audio-answer'], false).map(parseAnswer);
    return parseElement(question, childElements, {
        displayNumber: getAttribute(question, 'display-number'),
        maxAnswers: getNumericAttribute(question, 'max-answers')
    });
}
function parseAnswer(answer) {
    const attributes = {
        displayNumber: getAttribute(answer, 'display-number'),
        questionId: getNumericAttribute(answer, 'question-id'),
        maxLength: getNumericAttribute(answer, 'max-length')
    };
    return parseElement(answer, [], attributes);
}
function parseElement(element, childNodes, attributes) {
    return {
        name: element.localName,
        attributes,
        childNodes
    };
}
//# sourceMappingURL=parseExamStructure.js.map