"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = createHtmlValidatedQuizAtom;

var _handlebars = _interopRequireDefault(require("handlebars"));

var _templates = require("../templates");

var _utils = require("../utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Create HTML content for ValidatedQuizAtom
 * @param {object} atom atom json
 * @param {string} targetDir output directory path
 * @returns {string} HTML content
 */
async function createHtmlValidatedQuizAtom(atom, targetDir) {
  const prompt = await (0, _utils.createHtmlText)(atom.question.prompt, targetDir, atom.id);
  const matchers = [];

  for (let i = 0, len = atom.question.matchers; i < len; i += 1) {
    const matcher = matchers[i];
    matchers.push(matcher.expression);
  }

  const html = await (0, _templates.loadTemplate)('atom.validatedQuiz');

  const template = _handlebars.default.compile(html);

  const data = {
    prompt,
    matchers
  };
  return template(data);
}