"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useEventKey = exports["default"] = void 0;
var _utilEvent = _interopRequireDefault(require("@enact/ui/useScroll/utilEvent"));
var _react = require("react");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var useEventKey = exports.useEventKey = function useEventKey() {
  // Mutable value

  var mutableRef = (0, _react.useRef)({
    fn: null
  });

  // Functions

  function addGlobalKeyDownEventListener(fn) {
    mutableRef.current.fn = fn;
    (0, _utilEvent["default"])('keydown').addEventListener(document, mutableRef.current.fn, {
      capture: true
    });
  }
  function removeGlobalKeyDownEventListener() {
    (0, _utilEvent["default"])('keydown').removeEventListener(document, mutableRef.current.fn, {
      capture: true
    });
    mutableRef.current.fn = null;
  }

  // Return

  return {
    addGlobalKeyDownEventListener: addGlobalKeyDownEventListener,
    removeGlobalKeyDownEventListener: removeGlobalKeyDownEventListener
  };
};
var _default = exports["default"] = useEventKey;