"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Cursor = require("../../util/Cursor.js");
const ClickTrap = require("../../util/ClickTrap.js");
const PositionUtil = require("../../util/PositionUtil.js");
const index_esm = require("../../../../min-dom/dist/index.esm.js");
const Event = require("../../util/Event.js");
var y = 15;
function x(o, m) {
  var n;
  o.on("element.mousedown", 500, function(t) {
    return f(t.originalEvent);
  });
  function i(t) {
    var r = n.start, c = n.button, u = Event.toPoint(t), e = PositionUtil.delta(u, r);
    if (!n.dragging && M(e) > y && (n.dragging = true, c === 0 && ClickTrap.install(o), Cursor.set("grab")), n.dragging) {
      var g = n.last || n.start;
      e = PositionUtil.delta(u, g), m.scroll({
        dx: e.x,
        dy: e.y
      }), n.last = u;
    }
    t.preventDefault();
  }
  function s(t) {
    index_esm.event.unbind(document, "mousemove", i), index_esm.event.unbind(document, "mouseup", s), n = null, Cursor.unset();
  }
  function f(t) {
    if (!index_esm.closest(t.target, ".djs-draggable")) {
      var r = t.button;
      if (!(r >= 2 || t.ctrlKey || t.shiftKey || t.altKey))
        return n = {
          button: r,
          start: Event.toPoint(t)
        }, index_esm.event.bind(document, "mousemove", i), index_esm.event.bind(document, "mouseup", s), true;
    }
  }
  this.isActive = function() {
    return !!n;
  };
}
x.$inject = [
  "eventBus",
  "canvas"
];
function M(o) {
  return Math.sqrt(Math.pow(o.x, 2) + Math.pow(o.y, 2));
}
exports.default = x;
