"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 _ItemTypes = _interopRequireDefault(require("./ItemTypes"));
var _UUID = _interopRequireDefault(require("./UUID"));
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 ToolbarItem = function ToolbarItem(_ref) {
  var data = _ref.data,
    onClick = _ref.onClick,
    onCreate = _ref.onCreate;
  var ref = (0, _react.useRef)(null);
  var _useDrag = (0, _reactDnd.useDrag)(function () {
      return {
        type: _ItemTypes["default"].CARD,
        item: {
          id: _UUID["default"].uuid(),
          index: -1,
          data: data,
          onCreate: onCreate
        },
        collect: function collect(monitor) {
          return {
            isDragging: !!monitor.isDragging()
          };
        }
      };
    }),
    _useDrag2 = (0, _slicedToArray2["default"])(_useDrag, 2),
    drag = _useDrag2[1];
  drag(ref);
  return /*#__PURE__*/_react["default"].createElement("li", {
    ref: ref,
    onClick: onClick
  }, /*#__PURE__*/_react["default"].createElement("i", {
    className: data.icon
  }), data.name);
};
var _default = exports["default"] = ToolbarItem;