"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireWildcard(require("react"));
var _reactDnd = require("react-dnd");
var _reactDndHtml5Backend = require("react-dnd-html5-backend");
var _ItemTypes = _interopRequireDefault(require("../ItemTypes"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var style = {
  cursor: 'move'
};
var DragHandle = function DragHandle(props) {
  var data = props.data,
    index = props.index,
    onDestroy = props.onDestroy,
    setAsChild = props.setAsChild,
    getDataById = props.getDataById;

  //console.log('props', props);
  var _useDrag = (0, _reactDnd.useDrag)(function () {
      return {
        type: _ItemTypes["default"].BOX,
        item: {
          itemType: _ItemTypes["default"].BOX,
          index: data.parentId ? -1 : index,
          parentIndex: data.parentIndex,
          id: data.id,
          col: data.col,
          onDestroy: onDestroy,
          setAsChild: setAsChild,
          getDataById: getDataById,
          data: data
        },
        collect: function collect(monitor) {
          return {
            isDragging: !!monitor.isDragging()
          };
        }
      };
    }),
    _useDrag2 = (0, _slicedToArray2["default"])(_useDrag, 3),
    isDragging = _useDrag2[0].isDragging,
    drag = _useDrag2[1],
    preview = _useDrag2[2];
  (0, _react.useEffect)(function () {
    preview((0, _reactDndHtml5Backend.getEmptyImage)(), {
      captureDraggingState: true
    });
  }, [preview]);
  return /*#__PURE__*/_react["default"].createElement("div", {
    ref: drag,
    className: "btn is-isolated",
    style: style
  }, /*#__PURE__*/_react["default"].createElement("i", {
    className: "is-isolated fas fa-grip-vertical"
  }));
};
var _default = exports["default"] = DragHandle;