"use strict";
exports.__esModule = true;
exports.useGlobalKeys = void 0;
var react_1 = require("react");
var useGlobalKeys = function (keyHandlers, eventType) {
    if (eventType === void 0) { eventType = 'keyup'; }
    var keyHandlersRef = (0, react_1.useRef)({});
    (0, react_1.useEffect)(function () {
        keyHandlersRef.current = keyHandlers;
    }, [keyHandlers]);
    (0, react_1.useEffect)(function () {
        var handler = function (e) {
            var current = keyHandlersRef.current;
            var userHandler = current[e.code] || current[e.key];
            userHandler && userHandler(e);
        };
        document.addEventListener(eventType, handler);
        return function () {
            document.removeEventListener(eventType, handler);
        };
    }, [eventType]);
};
exports.useGlobalKeys = useGlobalKeys;
