'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
var defaults = {
  correct: { type: 'default', default: 'Correct', custom: 'Correct' },
  incorrect: { type: 'default', default: 'Incorrect', custom: 'Incorrect' },
  partial: { type: 'default', default: 'Nearly', custom: 'Nearly' }
};

/**
 * @typedef {Object} FeedbackConfig
 * @property {'default'|'none'|'custom'} type
 * @property {string} default
 * @property {string} custom
 *
 * @typedef {Object} Feedback
 *  @property {FeedbackConfig} correct
 *  @property {FeedbackConfig} incorrect
 *  @property {FeedbackConfig} partial
 */

var normalizeCorrectness = function normalizeCorrectness(c) {
  if (c === 'partially-correct') {
    return 'partial';
  }
  return c;
};

/**
 * Get the feedback for the correctness
 *
 * @param {'correct'|'incorrect'|'partial'} correctness
 * @param {Feedback} feedback
 */
var getFeedbackForCorrectness = exports.getFeedbackForCorrectness = function getFeedbackForCorrectness(correctness, feedback) {
  return new Promise(function (resolve) {
    correctness = normalizeCorrectness(correctness);
    var fb = feedback[correctness] || defaults[correctness] || {};
    var d = defaults[correctness] || {};
    getFeedback(fb, d[fb.type || 'default']).then(function (result) {
      return resolve(result);
    });
  });
};

/**
 * Get the feedback from a {FeedbackConfig}
 *
 * @param {FeedbackConfig} feedback
 * @param {string} fallback
 */
var getFeedback = exports.getFeedback = function getFeedback(feedback, fallback) {
  return new Promise(function (resolve) {
    if (!feedback || feedback.type === 'none') {
      resolve(undefined);
      return;
    }
    feedback = feedback || {};
    var out = feedback[feedback.type] || fallback;
    resolve(out);
  });
};