import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React from "react";
import { useDrag, DragPreviewImage } from "react-dnd";
var emptyImage = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
var Draggable = /*#__PURE__*/React.memo(function (props) {
  var children = props.children,
      beginDrag = props.beginDrag,
      endDrag = props.endDrag,
      target = props.target,
      element = props.element;

  var _useDrag = useDrag({
    item: {
      type: "element",
      target: target
    },
    collect: function collect(monitor) {
      return {
        isDragging: monitor.isDragging()
      };
    },
    begin: function begin(monitor) {
      if (typeof beginDrag === "function") {
        return beginDrag(props, monitor, element);
      }

      return _objectSpread({}, props);
    },
    end: function end(item, monitor) {
      if (typeof endDrag === "function") {
        return endDrag(item, monitor);
      }
    }
  }),
      _useDrag2 = _slicedToArray(_useDrag, 3),
      isDragging = _useDrag2[0].isDragging,
      drag = _useDrag2[1],
      preview = _useDrag2[2];

  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DragPreviewImage, {
    connect: preview,
    src: emptyImage
  }), children({
    isDragging: isDragging,
    drag: drag
  }));
});
export default Draggable;
//# sourceMappingURL=Draggable.js.map