"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.getInstanceOfDraggableTarget = exports.getInstanceOfDraggableSource = exports.getInstanceOfDraggableProvider = void 0;
var _testUtils = _interopRequireDefault(require("react-dom/test-utils"));
var findInstance = (wrapper, cb) => {
  var itemInstance = null;
  _testUtils.default.findAllInRenderedTree(wrapper, ins => {
    var portalRoot = ins && (ins.portal || ins.tooltipContent);
    if (portalRoot && _testUtils.default.isCompositeComponent(portalRoot)) {
      return _testUtils.default.findAllInRenderedTree(portalRoot, insInPortal => {
        if (cb(insInPortal)) {
          itemInstance = insInPortal;
        }
        return Boolean(itemInstance);
      });
    } else if (cb(ins)) {
      itemInstance = ins;
    }
    return Boolean(itemInstance);
  });
  return itemInstance;
};
var getInstanceOfDraggableProvider = wrapper => findInstance(wrapper, ins => {
  var _ins$props;
  return ins == null || (_ins$props = ins.props) == null ? void 0 : _ins$props.backend;
});
exports.getInstanceOfDraggableProvider = getInstanceOfDraggableProvider;
var getInstanceOfDraggableSource = (wrapper, itemId) => findInstance(wrapper, ins => {
  var _ins$handler;
  return (ins == null || (_ins$handler = ins.handler) == null ? void 0 : _ins$handler.monitor.sourceId) && ins.props.id === itemId;
});
exports.getInstanceOfDraggableSource = getInstanceOfDraggableSource;
var getInstanceOfDraggableTarget = (wrapper, itemId) => findInstance(wrapper, ins => {
  var _ins$handler2;
  return (ins == null || (_ins$handler2 = ins.handler) == null ? void 0 : _ins$handler2.monitor.targetId) && ins.props.id === itemId;
});
exports.getInstanceOfDraggableTarget = getInstanceOfDraggableTarget;
//# sourceMappingURL=dragAndDropTestUtils.js.map