var lib = {};

var interopRequireDefault = {exports: {}};

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

module.exports = _interopRequireDefault, module.exports.__esModule = true, module.exports["default"] = module.exports;
}(interopRequireDefault));

var defineProperty = {exports: {}};

(function (module) {
function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
}(defineProperty));

var defaults = {};

(function (exports) {

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _default = {
  points: ['', '', '', ''],
  sampleAnswers: [null, null, null, null],
  maxPoints: 3,
  maxPointsEnabled: true,
  excludeZero: false,
  excludeZeroEnabled: true
};
exports["default"] = _default;

}(defaults));

var _interopRequireDefault = interopRequireDefault.exports;

Object.defineProperty(lib, "__esModule", {
  value: true
});
var model_1 = lib.model = model;
var validate_1 = lib.validate = validate;

var _defineProperty2 = _interopRequireDefault(defineProperty.exports);

var _defaults = _interopRequireDefault(defaults);

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

var normalize = function normalize(model) {
  return _objectSpread(_objectSpread({}, _defaults["default"]), model);
};

function model(model, session, env) {
  return new Promise(function (resolve) {
    var modelResult = normalize(model || {});
    resolve(env && env.role && env.role === 'instructor' ? modelResult : {});
  });
}

function markupToText(s) {
  return (s || '').replace(/(<([^>]+)>)/gi, '');
} // IMPORTANT! If you make any changes to this function, please make sure you also update complex-rubric/controller/validateSimpleRubric function!“.


function validate(model) {
  var points = model.points;
  var errors = {};
  var pointsDescriptorsErrors = {};
  (points || []).forEach(function (point, index) {
    if (!point || point === '<div></div>') {
      pointsDescriptorsErrors[index] = 'Points descriptors cannot be empty.';
    } else {
      var identicalPointDescr = points.slice(index + 1).some(function (p) {
        return markupToText(p) === markupToText(point);
      });

      if (identicalPointDescr) {
        pointsDescriptorsErrors[index] = 'Points descriptors should be unique.';
      }
    }
  });

  if (Object.keys(pointsDescriptorsErrors).length > 0) {
    errors.pointsDescriptorsErrors = pointsDescriptorsErrors;
  }

  return errors;
}

export { lib as default, model_1 as model, validate_1 as validate };
