"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.isRichEditorFocused = exports.getContent = exports.focusRichEditor = exports.enterRichTextValue = exports.blurRichEditor = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _testUtils = _interopRequireDefault(require("react-dom/test-utils"));
var _ReactBase = require("./ReactBase");
var _actCompat = require("./actCompat");
var _ = require(".");
/** Receives a unidriver of container that wraps a DraftJS input
 * and returns the input content element */
var getContent = base => base.$('.public-DraftEditor-content');

/** Receives a unidriver of container (base) that wraps a DraftJS input,
 * and a `value` to add to the input
 * adds the value to the current input value */
exports.getContent = getContent;
var enterRichTextValue = exports.enterRichTextValue = /*#__PURE__*/function () {
  var _ref = (0, _asyncToGenerator2.default)(function* (base, value) {
    var contentElement = getContent(base);
    var nativeElement = yield contentElement.getNative();
    if (contentElement.type === 'react') {
      yield (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
        _testUtils.default.Simulate.beforeInput(nativeElement, {
          data: value
        });
      }));
    } else if (contentElement.type === 'puppeteer') {
      yield contentElement.enterValue(value, {
        shouldClear: false
      });
    } else {
      throw new Error('unsupported adapter');
    }
  });
  return function enterRichTextValue(_x, _x2) {
    return _ref.apply(this, arguments);
  };
}();
var focusRichEditor = exports.focusRichEditor = /*#__PURE__*/function () {
  var _ref3 = (0, _asyncToGenerator2.default)(function* (base) {
    switch (base.type) {
      case 'react':
        return (0, _ReactBase.ReactBase)(getContent(base)).focus();
      case 'puppeteer':
        var {
          element
        } = yield getContent(base).getNative();
        return element.focus();
      default:
        throw new Error('unsupported adapter');
    }
  });
  return function focusRichEditor(_x3) {
    return _ref3.apply(this, arguments);
  };
}();
var blurRichEditor = exports.blurRichEditor = /*#__PURE__*/function () {
  var _ref4 = (0, _asyncToGenerator2.default)(function* (base) {
    switch (base.type) {
      case 'react':
        return (0, _ReactBase.ReactBase)(getContent(base)).blur();
      case 'puppeteer':
        var {
          element
        } = yield getContent(base).getNative();
        return element.blur();
      default:
        throw new Error('unsupported adapter');
    }
  });
  return function blurRichEditor(_x4) {
    return _ref4.apply(this, arguments);
  };
}();
var isRichEditorFocused = exports.isRichEditorFocused = /*#__PURE__*/function () {
  var _ref5 = (0, _asyncToGenerator2.default)(function* (base) {
    return (0, _.isElementFocused)(getContent(base));
  });
  return function isRichEditorFocused(_x5) {
    return _ref5.apply(this, arguments);
  };
}();
//# sourceMappingURL=DraftJS.js.map