"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireDefault(require("react"));
var _TouchBackend = _interopRequireDefault(require("./TouchBackend"));
var _reactDnd = require("react-dnd");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/DragDropContextProvider/DragDropContextProvider.jsx";
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
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; }
var defaultManager;
function getDefaultManager(backend) {
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  if (!defaultManager) {
    defaultManager = (0, _reactDnd.createDndContext)(backend, {}, _objectSpread({
      enableMouseEvents: true
    }, options)).dragDropManager;
  }
  return defaultManager;
}

// https://github.com/react-dnd/react-dnd/issues/186#issuecomment-110333064
var DragDropContextProvider = /*#__PURE__*/function (_React$Component) {
  function DragDropContextProvider() {
    (0, _classCallCheck2["default"])(this, DragDropContextProvider);
    return _callSuper(this, DragDropContextProvider, arguments);
  }
  (0, _inherits2["default"])(DragDropContextProvider, _React$Component);
  return (0, _createClass2["default"])(DragDropContextProvider, [{
    key: "getManager",
    value:
    // we add `manager` to instance to allow to manipulate d&d in tests
    function getManager() {
      return this.context.dragDropManager || getDefaultManager(this.props.backend, this.props.backendOptions);
    }
  }, {
    key: "getChildContext",
    value: function getChildContext() {
      return {
        dragDropManager: this.getManager()
      };
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
        backend = _this$props.backend,
        children = _this$props.children;
      return /*#__PURE__*/_react["default"].createElement(_reactDnd.DndProvider, {
        manager: this.getManager(backend),
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 54,
          columnNumber: 7
        }
      }, children);
    }
  }]);
}(_react["default"].Component);
DragDropContextProvider.defaultProps = {
  backend: _TouchBackend["default"],
  backendOptions: {}
};
DragDropContextProvider.contextTypes = {
  dragDropManager: function dragDropManager() {
    return null;
  }
};
DragDropContextProvider.childContextTypes = {
  dragDropManager: function dragDropManager() {
    return null;
  }
};
var _default = exports["default"] = DragDropContextProvider;