"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useDelayedDragEventCall = void 0;
var react_1 = require("react");
var ramda_1 = require("ramda");
var DELAY_TIMEOUT = 50;
var useDelayedDragEventCall = function (callback, delay) {
    if (delay === void 0) { delay = DELAY_TIMEOUT; }
    var prevMousePosition = (0, react_1.useRef)(null);
    var lastTimeChanged = (0, react_1.useRef)(0);
    return (0, react_1.useCallback)(function (_a) {
        var event = _a.event, node = _a.node;
        var now = Date.now();
        var newMousePosition = { x: event.clientX, y: event.clientY };
        if (!(0, ramda_1.equals)(prevMousePosition === null || prevMousePosition === void 0 ? void 0 : prevMousePosition.current, newMousePosition)) {
            lastTimeChanged.current = now;
        }
        var waitedTime = now - (lastTimeChanged === null || lastTimeChanged === void 0 ? void 0 : lastTimeChanged.current);
        if (waitedTime > delay) {
            lastTimeChanged.current = now;
            callback({ event: event, node: node });
        }
        prevMousePosition.current = newMousePosition;
    }, [callback, delay]);
};
exports.useDelayedDragEventCall = useDelayedDragEventCall;
