import { useCallback, useRef } from 'react';
import { equals } from 'ramda';
var DELAY_TIMEOUT = 50;
export var useDelayedDragEventCall = function (callback, delay) {
    if (delay === void 0) { delay = DELAY_TIMEOUT; }
    var prevMousePosition = useRef(null);
    var lastTimeChanged = useRef(0);
    return useCallback(function (_a) {
        var event = _a.event, node = _a.node;
        var now = Date.now();
        var newMousePosition = { x: event.clientX, y: event.clientY };
        if (!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]);
};
