"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isNumber = exports.insertSnackBar = exports.getDefaultElement = exports.defaultIDD = exports.defaultECR = exports.defaultDIB = void 0;

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

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

var _slate = require("slate");

var _Snackbar = _interopRequireDefault(require("@material-ui/core/Snackbar"));

var isNumber = function isNumber(val) {
  return !isNaN(parseFloat(val)) && isFinite(val);
};

exports.isNumber = isNumber;

var insertSnackBar = function insertSnackBar(message) {
  var prevSnacks = document.querySelectorAll('.response-area-alert');
  prevSnacks.forEach(function (s) {
    return s.remove();
  });
  var newEl = document.createElement('div');
  newEl.className = 'response-area-alert';

  var el = /*#__PURE__*/_react["default"].createElement(_Snackbar["default"], {
    anchorOrigin: {
      vertical: 'top',
      horizontal: 'center'
    },
    open: true,
    ContentProps: {
      'aria-describedby': 'message-id'
    },
    message: /*#__PURE__*/_react["default"].createElement("span", {
      id: "message-id"
    }, message)
  });

  _reactDom["default"].render(el, newEl);

  document.body.appendChild(newEl);
  setTimeout(function () {
    newEl.remove();
  }, 2000);
};

exports.insertSnackBar = insertSnackBar;

var defaultECR = function defaultECR(index) {
  return _slate.Inline.create({
    type: 'explicit_constructed_response',
    isVoid: true,
    data: {
      index: index
    }
  });
};

exports.defaultECR = defaultECR;

var defaultDIB = function defaultDIB(opts, index) {
  return _slate.Inline.create({
    type: 'drag_in_the_blank',
    isVoid: true,
    data: {
      index: index,
      duplicates: opts.options.duplicates,
      value: null
    }
  });
};

exports.defaultDIB = defaultDIB;

var defaultIDD = function defaultIDD(index) {
  return _slate.Inline.create({
    object: 'inline',
    type: 'inline_dropdown',
    isVoid: true,
    data: {
      index: index
    }
  });
};

exports.defaultIDD = defaultIDD;

var getDefaultElement = function getDefaultElement(opts, index) {
  switch (opts.type) {
    case 'explicit-constructed-response':
      return defaultECR(index);

    case 'drag-in-the-blank':
      return defaultDIB(opts, index);

    default:
      // inline-dropdown
      return defaultIDD(index);
  }
};

exports.getDefaultElement = getDefaultElement;
//# sourceMappingURL=utils.js.map