function _extends() {
  _extends = Object.assign || function (target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];

      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }

    return target;
  };

  return _extends.apply(this, arguments);
}

var defaults = {
  points: ['', '', '', ''],
  sampleAnswers: [null, null, null, null],
  maxPoints: 3,
  maxPointsEnabled: true,
  excludeZero: false,
  excludeZeroEnabled: true
};

const normalize = model => _extends({}, defaults, model);

function model(model, session, env) {
  return new Promise(resolve => {
    const 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) {
  const {
    points
  } = model;
  const errors = {};
  const pointsDescriptorsErrors = {};
  (points || []).forEach((point, index) => {
    if (!point || point === '<div></div>') {
      pointsDescriptorsErrors[index] = 'Points descriptors cannot be empty.';
    } else {
      const identicalPointDescr = points.slice(index + 1).some(p => 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 { model, validate };
//# sourceMappingURL=controller.js.map
