"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _rubric = _interopRequireDefault(require("@pie-element/rubric"));

var _multiTraitRubric = _interopRequireDefault(require("@pie-element/multi-trait-rubric"));

var _rubric2 = require("@pie-lib/rubric");

var _rubricTags;

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; }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var RUBRIC_TAG_NAME = 'complex-rubric-simple';
var MULTI_TRAIT_RUBRIC_TAG_NAME = 'complex-rubric-multi-trait';

var ComplexRubricSimple = /*#__PURE__*/function (_Rubric) {
  (0, _inherits2["default"])(ComplexRubricSimple, _Rubric);

  var _super = _createSuper(ComplexRubricSimple);

  function ComplexRubricSimple() {
    (0, _classCallCheck2["default"])(this, ComplexRubricSimple);
    return _super.apply(this, arguments);
  }

  return (0, _createClass2["default"])(ComplexRubricSimple);
}(_rubric["default"]);

var ComplexRubricMultiTrait = /*#__PURE__*/function (_MultiTraitRubric) {
  (0, _inherits2["default"])(ComplexRubricMultiTrait, _MultiTraitRubric);

  var _super2 = _createSuper(ComplexRubricMultiTrait);

  function ComplexRubricMultiTrait() {
    (0, _classCallCheck2["default"])(this, ComplexRubricMultiTrait);
    return _super2.apply(this, arguments);
  }

  return (0, _createClass2["default"])(ComplexRubricMultiTrait);
}(_multiTraitRubric["default"]);

var rubricTags = (_rubricTags = {}, (0, _defineProperty2["default"])(_rubricTags, _rubric2.RUBRIC_TYPES.SIMPLE_RUBRIC, "<".concat(RUBRIC_TAG_NAME, " id=\"simpleRubric\" />")), (0, _defineProperty2["default"])(_rubricTags, _rubric2.RUBRIC_TYPES.RUBRICLESS, "<".concat(RUBRIC_TAG_NAME, " id=\"rubricless\" />")), (0, _defineProperty2["default"])(_rubricTags, _rubric2.RUBRIC_TYPES.MULTI_TRAIT_RUBRIC, "<".concat(MULTI_TRAIT_RUBRIC_TAG_NAME, " id=\"multiTraitRubric\" />")), _rubricTags);

var preparePrintModel = function preparePrintModel(model, opts) {
  var instr = opts.role === 'instructor';

  if (!instr) {
    return {};
  }

  model.mode = 'evaluate';
  model.animationsDisabled = true;
  return model;
};

var defineRubrics = function defineRubrics() {
  if (!customElements.get(RUBRIC_TAG_NAME)) {
    customElements.define(RUBRIC_TAG_NAME, ComplexRubricSimple);
  }

  if (!customElements.get(MULTI_TRAIT_RUBRIC_TAG_NAME)) {
    customElements.define(MULTI_TRAIT_RUBRIC_TAG_NAME, ComplexRubricMultiTrait);
  }
};

defineRubrics();

var ComplexRubricPrint = /*#__PURE__*/function (_HTMLElement) {
  (0, _inherits2["default"])(ComplexRubricPrint, _HTMLElement);

  var _super3 = _createSuper(ComplexRubricPrint);

  function ComplexRubricPrint() {
    var _this;

    (0, _classCallCheck2["default"])(this, ComplexRubricPrint);
    _this = _super3.call(this);
    _this._model = {};
    _this._type = _rubric2.RUBRIC_TYPES.SIMPLE_RUBRIC;
    _this._options = null;
    return _this;
  }

  (0, _createClass2["default"])(ComplexRubricPrint, [{
    key: "type",
    get: function get() {
      return this._type;
    },
    set: function set(t) {
      this._type = t;
    }
  }, {
    key: "model",
    set: function set(m) {
      var _this2 = this;

      this._model = m;
      var oldType = this._type;
      this.type = m.rubricType;

      switch (this._type) {
        case _rubric2.RUBRIC_TYPES.SIMPLE_RUBRIC:
        default:
          customElements.whenDefined(RUBRIC_TAG_NAME).then(function () {
            _this2.setRubricModel(_this2.simpleRubric);
          });
          break;

        case _rubric2.RUBRIC_TYPES.MULTI_TRAIT_RUBRIC:
          customElements.whenDefined(MULTI_TRAIT_RUBRIC_TAG_NAME).then(function () {
            _this2.setMultiTraitRubricModel(_this2.multiTraitRubric);
          });
          break;

        case _rubric2.RUBRIC_TYPES.RUBRICLESS:
          customElements.whenDefined(RUBRIC_TAG_NAME).then(function () {
            _this2.setRubriclessModel(_this2.rubricless);
          });
          break;
      }

      if (oldType !== this.type) {
        this._render();
      }
    }
  }, {
    key: "setRubricModel",
    value: function setRubricModel(simpleRubric) {
      if (this._model && this._model.rubrics && this._model.rubrics.simpleRubric) {
        simpleRubric.model = preparePrintModel(this._model.rubrics.simpleRubric, this._options);
      }
    }
  }, {
    key: "setMultiTraitRubricModel",
    value: function setMultiTraitRubricModel(multiTraitRubric) {
      if (this._model && this._model.rubrics && this._model.rubrics.multiTraitRubric) {
        var _ref = this._model.rubrics.multiTraitRubric || {},
            scales = _ref.scales,
            excludeZero = _ref.excludeZero;

        var parsedScales = (scales || []).map(function (scale) {
          return _objectSpread(_objectSpread({}, scale), {}, {
            excludeZero: excludeZero
          });
        });
        multiTraitRubric.model = _objectSpread(_objectSpread({}, preparePrintModel(this._model.rubrics.multiTraitRubric, this._options)), {}, {
          visible: true,
          arrowsDisabled: true,
          scales: parsedScales
        });
      }
    }
  }, {
    key: "setRubriclessModel",
    value: function setRubriclessModel(rubricless) {
      if (this._model && this._model.rubrics && this._model.rubrics.rubricless) {
        rubricless.model = preparePrintModel(this._model.rubrics.rubricless, this._options);
      }
    }
  }, {
    key: "options",
    set: function set(o) {
      this._options = o;
    }
  }, {
    key: "multiTraitRubric",
    get: function get() {
      return this.querySelector("".concat(MULTI_TRAIT_RUBRIC_TAG_NAME, "#multiTraitRubric"));
    }
  }, {
    key: "simpleRubric",
    get: function get() {
      return this.querySelector("".concat(RUBRIC_TAG_NAME, "#simpleRubric"));
    }
  }, {
    key: "rubricless",
    get: function get() {
      return this.querySelector("".concat(RUBRIC_TAG_NAME, "#rubricless"));
    }
  }, {
    key: "connectedCallback",
    value: function connectedCallback() {
      this._render();
    }
  }, {
    key: "_render",
    value: function _render() {
      this.innerHTML = rubricTags[this._type] || '';
    }
  }]);
  return ComplexRubricPrint;
}( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(HTMLElement));

var _default = ComplexRubricPrint;
exports["default"] = _default;
//# sourceMappingURL=print.js.map