"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const aria = require("../../constants/aria.js");
const event = require("../../utils/dom/event.js");
const vue = require("vue");
const index = require("../../../node_modules/@vueuse/shared/index.js");
let registeredEscapeHandlers = [];
const cachedHandler = (event$1) => {
  if (event.getEventCode(event$1) === aria.EVENT_CODE.esc) registeredEscapeHandlers.forEach((registeredHandler) => registeredHandler(event$1));
};
const useEscapeKeydown = (handler) => {
  vue.onMounted(() => {
    if (registeredEscapeHandlers.length === 0) document.addEventListener("keydown", cachedHandler);
    if (index.isClient) registeredEscapeHandlers.push(handler);
  });
  vue.onBeforeUnmount(() => {
    registeredEscapeHandlers = registeredEscapeHandlers.filter((registeredHandler) => registeredHandler !== handler);
    if (registeredEscapeHandlers.length === 0) {
      if (index.isClient) document.removeEventListener("keydown", cachedHandler);
    }
  });
};
exports.useEscapeKeydown = useEscapeKeydown;
