"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.ReactBase = ReactBase;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _testUtils = require("react-dom/test-utils");
var _actCompat = require("./actCompat");
var _vanilla = require("@wix/wix-ui-test-utils/vanilla");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
/**
 *Temporary workaround for implementing missing Unidriver methods in React/DOM only.
 *
 * @param {UniDriver} base
 */
function ReactBase(base) {
  var htmlElement = () => {
    if (base.type !== 'react' && base.type !== 'dom') {
      throw new Error('Supported only in React/DOM.');
    }
    return base.getNative();
  };
  var pendingUnidriverFeatures = {
    isFocus: function () {
      var _isFocus = (0, _asyncToGenerator2.default)(function* () {
        return document.activeElement === (yield htmlElement());
      });
      function isFocus() {
        return _isFocus.apply(this, arguments);
      }
      return isFocus;
    }(),
    paste: function () {
      var _paste = (0, _asyncToGenerator2.default)(function* () {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return _testUtils.Simulate.paste(yield htmlElement());
        }));
      });
      function paste() {
        return _paste.apply(this, arguments);
      }
      return paste;
    }(),
    copy: function () {
      var _copy = (0, _asyncToGenerator2.default)(function* () {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return _testUtils.Simulate.copy(yield htmlElement());
        }));
      });
      function copy() {
        return _copy.apply(this, arguments);
      }
      return copy;
    }(),
    select: function () {
      var _select = (0, _asyncToGenerator2.default)(function* (selectedIndex) {
        var element = yield htmlElement();
        if (!element.disabled) {
          yield (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
            _testUtils.Simulate.change(element, {
              target: {
                selectedIndex,
                value: ''
              }
            });
          }));
        }
      });
      function select(_x) {
        return _select.apply(this, arguments);
      }
      return select;
    }(),
    drop: function () {
      var _drop = (0, _asyncToGenerator2.default)(function* (eventData) {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return _testUtils.Simulate.drop(yield htmlElement(), eventData);
        }));
      });
      function drop(_x2) {
        return _drop.apply(this, arguments);
      }
      return drop;
    }()
  };
  var unidriverRejected = {
    // Event Simulation
    focus: function () {
      var _focus = (0, _asyncToGenerator2.default)(function* () {
        var elm = yield htmlElement();
        yield (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          elm.focus();
          _testUtils.Simulate.focus(elm); // TODO: Is this redundant?
        }));
      });
      function focus() {
        return _focus.apply(this, arguments);
      }
      return focus;
    }(),
    blur: function () {
      var _blur = (0, _asyncToGenerator2.default)(function* () {
        var elm = yield htmlElement();
        yield (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          elm.blur();
          _testUtils.Simulate.blur(elm); // TODO: Is this redundant?
        }));
      });
      function blur() {
        return _blur.apply(this, arguments);
      }
      return blur;
    }()
  };

  // Instead of using this methods you should use proper data hooks
  // and data attributes the query the required elements
  var deprecated = {
    _DEPRECATED_getClassList: function () {
      var _DEPRECATED_getClassList2 = (0, _asyncToGenerator2.default)(function* () {
        return (yield htmlElement()).classList;
      });
      function _DEPRECATED_getClassList() {
        return _DEPRECATED_getClassList2.apply(this, arguments);
      }
      return _DEPRECATED_getClassList;
    }(),
    /** @returns {array} array of children unidrivers */
    _DEPRECATED_children: function () {
      var _DEPRECATED_children2 = (0, _asyncToGenerator2.default)(function* () {
        var ch = (yield htmlElement()).children;
        var uniChildren = [];
        for (var i = 0; i < ch.length; i++) {
          uniChildren.push((0, _vanilla.reactUniDriver)(ch[i]));
        }
        return uniChildren;
      });
      function _DEPRECATED_children() {
        return _DEPRECATED_children2.apply(this, arguments);
      }
      return _DEPRECATED_children;
    }()
  };
  var shouldBePrivate = {
    wheel: function () {
      var _wheel = (0, _asyncToGenerator2.default)(function* (eventData) {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return _testUtils.Simulate.wheel(yield htmlElement(), eventData);
        }));
      });
      function wheel(_x3) {
        return _wheel.apply(this, arguments);
      }
      return wheel;
    }(),
    keyUp: function () {
      var _keyUp = (0, _asyncToGenerator2.default)(function* (eventData) {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return _testUtils.Simulate.keyUp(yield htmlElement(), eventData);
        }));
      });
      function keyUp(_x4) {
        return _keyUp.apply(this, arguments);
      }
      return keyUp;
    }(),
    keyDown: function () {
      var _keyDown = (0, _asyncToGenerator2.default)(function* (eventData) {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return _testUtils.Simulate.keyDown(yield htmlElement(), eventData);
        }));
      });
      function keyDown(_x5) {
        return _keyDown.apply(this, arguments);
      }
      return keyDown;
    }(),
    mouseEnter: function () {
      var _mouseEnter = (0, _asyncToGenerator2.default)(function* (eventData) {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return _testUtils.Simulate.mouseEnter(yield htmlElement(), eventData);
        }));
      });
      function mouseEnter(_x6) {
        return _mouseEnter.apply(this, arguments);
      }
      return mouseEnter;
    }(),
    mouseLeave: function () {
      var _mouseLeave = (0, _asyncToGenerator2.default)(function* (eventData) {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return _testUtils.Simulate.mouseLeave(yield htmlElement(), eventData);
        }));
      });
      function mouseLeave(_x7) {
        return _mouseLeave.apply(this, arguments);
      }
      return mouseLeave;
    }(),
    beforeInput: function () {
      var _beforeInput = (0, _asyncToGenerator2.default)(function* (eventData) {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return (0, _testUtils.Simulate)(yield (yield htmlElement()).getNative(), new InputEvent('beforeinput', eventData));
        }));
      });
      function beforeInput(_x8) {
        return _beforeInput.apply(this, arguments);
      }
      return beforeInput;
    }()
  };
  var _private = {
    mouseDown: function () {
      var _mouseDown = (0, _asyncToGenerator2.default)(function* (eventData) {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return _testUtils.Simulate.mouseDown(yield htmlElement(), eventData);
        }));
      });
      function mouseDown(_x9) {
        return _mouseDown.apply(this, arguments);
      }
      return mouseDown;
    }(),
    mouseOver: function () {
      var _mouseOver = (0, _asyncToGenerator2.default)(function* (eventData) {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return _testUtils.Simulate.mouseOver(yield htmlElement(), eventData);
        }));
      });
      function mouseOver(_x0) {
        return _mouseOver.apply(this, arguments);
      }
      return mouseOver;
    }(),
    mouseOut: function () {
      var _mouseOut = (0, _asyncToGenerator2.default)(function* (eventData) {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return _testUtils.Simulate.mouseOut(yield htmlElement(), eventData);
        }));
      });
      function mouseOut(_x1) {
        return _mouseOut.apply(this, arguments);
      }
      return mouseOut;
    }(),
    compositionStart: function () {
      var _compositionStart = (0, _asyncToGenerator2.default)(function* () {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return _testUtils.Simulate.compositionStart(yield htmlElement());
        }));
      });
      function compositionStart() {
        return _compositionStart.apply(this, arguments);
      }
      return compositionStart;
    }(),
    compositionEnd: function () {
      var _compositionEnd = (0, _asyncToGenerator2.default)(function* () {
        return (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
          return _testUtils.Simulate.compositionEnd(yield htmlElement());
        }));
      });
      function compositionEnd() {
        return _compositionEnd.apply(this, arguments);
      }
      return compositionEnd;
    }()
  };
  return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, pendingUnidriverFeatures), unidriverRejected), deprecated), shouldBePrivate), {}, {
    _private // should be used inside private drivers only
  });
}

/*
 Deprecated - still here for backward compatibility.
 No need to use it inside new drivers, because drivers should not expose clickOutside functions.
 Tests should click on the outside container regardless easily without the help of a driver.
  */
ReactBase.clickBody = () => (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
  return document.body.dispatchEvent(new Event('mouseup', {
    cancelable: true,
    bubbles: true
  }));
}));
// TODO: Find out why some tests need clickOutSide to be on document and some on body
ReactBase.clickDocument = () => (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
  return document.dispatchEvent(new Event('mousedown', {
    cancelable: true,
    bubbles: true
  }));
}));
//# sourceMappingURL=ReactBase.js.map