"use strict";

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

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

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

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

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

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 _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));

var _react = _interopRequireDefault(require("react"));

var _reactDom = _interopRequireDefault(require("react-dom"));

var _debounce = _interopRequireDefault(require("lodash/debounce"));

var _main = _interopRequireDefault(require("./main"));

var _mathRenderingAccessible = require("@pie-lib/pie-toolbox/math-rendering-accessible");

var _debug = _interopRequireDefault(require("debug"));

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 log = (0, _debug["default"])('pie-element:select-text:print');
/**
 * Live in same package as main element - so we can access some of the shared comps!
 *
 * - update pslb to build print if src/print.js is there
 * - update demo el
 * - get configure/controller building
 */

var preparePrintModel = function preparePrintModel(model, opts) {
  var instr = opts.role === 'instructor';
  model.prompt = model.promptEnabled !== false ? model.prompt : undefined;
  model.teacherInstructions = instr && model.teacherInstructionsEnabled !== false ? model.teacherInstructions : undefined;
  model.rationale = instr && model.rationaleEnabled !== false ? model.rationale : undefined;
  model.showTeacherInstructions = instr;
  model.alwaysShowCorrect = instr;
  model.mode = instr ? 'evaluate' : model.mode;
  model.disabled = true;
  model.animationsDisabled = true;
  model.highlightChoices = true;
  model.feedback = undefined;
  return model;
};

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

  var _super = _createSuper(SelectTextPrint);

  function SelectTextPrint() {
    var _this;

    (0, _classCallCheck2["default"])(this, SelectTextPrint);
    _this = _super.call(this);
    _this._options = null;
    _this._model = null;
    _this._session = {};
    _this._session.selectedTokens = [];
    _this._rerender = (0, _debounce["default"])(function () {
      if (_this._model && _this._session) {
        var printModel = preparePrintModel(_this._model, _this._options);

        var element = _this._options && /*#__PURE__*/_react["default"].createElement(_main["default"], {
          model: printModel,
          session: {
            selectedTokens: []
          },
          onSelectionChange: function onSelectionChange() {}
        });

        _reactDom["default"].render(element, (0, _assertThisInitialized2["default"])(_this), function () {
          log('render complete - render math');
          (0, _mathRenderingAccessible.renderMath)((0, _assertThisInitialized2["default"])(_this));
        });
      } else {
        log('skip');
      }
    }, 50, {
      leading: false,
      trailing: true
    });
    return _this;
  }

  (0, _createClass2["default"])(SelectTextPrint, [{
    key: "options",
    set: function set(o) {
      this._options = o;
    }
  }, {
    key: "model",
    set: function set(s) {
      this._model = s;

      this._rerender();
    }
  }, {
    key: "connectedCallback",
    value: function connectedCallback() {}
  }]);
  return SelectTextPrint;
}( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(HTMLElement));

exports["default"] = SelectTextPrint;
//# sourceMappingURL=print.js.map