"use strict";

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

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

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

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

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

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

var _piePlayerEvents = require("@pie-framework/pie-player-events");

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

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

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 InlineDropdown = /*#__PURE__*/function (_HTMLElement) {
  (0, _inherits2["default"])(InlineDropdown, _HTMLElement);

  var _super = _createSuper(InlineDropdown);

  function InlineDropdown() {
    var _this;

    (0, _classCallCheck2["default"])(this, InlineDropdown);
    _this = _super.call(this);
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_render", function () {
      if (_this._model && _this._session) {
        var elem = /*#__PURE__*/_react["default"].createElement(_main["default"], {
          choices: _this._model.choices,
          disabled: _this._model.disabled,
          displayType: _this._model.displayType,
          feedback: _this._model.feedback,
          language: _this._model.language,
          markup: _this._model.markup,
          maxLengthPerChoice: _this._model.maxLengthPerChoice,
          maxLengthPerChoiceEnabled: _this._model.maxLengthPerChoiceEnabled,
          mode: _this._model.mode,
          note: _this._model.note,
          onChange: _this.changeSession,
          playerSpellCheckEnabled: _this._model.playerSpellCheckEnabled,
          prompt: _this._model.prompt,
          rationale: _this._model.rationale,
          role: _this._model.role,
          showNote: _this._model.showNote,
          teacherInstructions: _this._model.teacherInstructions,
          value: _this._session.value
        });

        _reactDom["default"].render(elem, (0, _assertThisInitialized2["default"])(_this), function () {
          (0, _mathRenderingAccessible.renderMath)((0, _assertThisInitialized2["default"])(_this));
        });
      }
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "dispatchChangedEvent", function () {
      _this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(_this.tagName.toLowerCase(), _this.session && !!_this.session.value));
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeSession", function (value) {
      _this.session.value = value;

      _this.dispatchChangedEvent();

      _this._render();
    });
    _this._model = null;
    _this._session = null;
    return _this;
  }

  (0, _createClass2["default"])(InlineDropdown, [{
    key: "setLangAttribute",
    value: function setLangAttribute() {
      var language = this._model && (0, _typeof2["default"])(this._model.language) ? this._model.language : '';
      var lang = language ? language.slice(0, 2) : 'en';
      this.setAttribute('lang', lang);
    }
  }, {
    key: "model",
    set: function set(m) {
      this._model = m;
      this.dispatchEvent(new _piePlayerEvents.ModelSetEvent(this.tagName.toLowerCase(), this.session && !!this.session.value, !!this._model));
      this.setLangAttribute();

      this._render();
    }
  }, {
    key: "session",
    get: function get() {
      return this._session;
    },
    set: function set(s) {
      this._session = s;

      this._render();
    }
  }, {
    key: "connectedCallback",
    value: function connectedCallback() {
      this.setAttribute('aria-label', 'Fill in the Blank Question');
      this.setAttribute('role', 'region');

      this._render();
    }
  }]);
  return InlineDropdown;
}( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(HTMLElement));

exports["default"] = InlineDropdown;
//# sourceMappingURL=index.js.map