text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.useEventListener = void 0;
  var vue_1 = require("vue");
  var onMountedOrActivated_1 = require("../onMountedOrActivated");
  var utils_1 = require("../utils");
  var supportsPassive = false;
  if (utils_1.inBrowser) {
      try {
          var opts = {};
          Object.defineProperty(opts, 'passive', {
              get: function () {
                  supportsPassive = true;
              },
          });
          window.addEventListener('test-passive', null, opts);
          // eslint-disable-next-line no-empty
      }
      catch (e) { }
  }
  function useEventListener(type, listener, options) {
      if (options === void 0) { options = {}; }
      if (!utils_1.inBrowser) {
          return;
      }
      var _a = options.target, target = _a === void 0 ? window : _a, _b = options.passive, passive = _b === void 0 ? false : _b, _c = options.capture, capture = _c === void 0 ? false : _c;
      var attached;
      var add = function () {
          var element = vue_1.unref(target);
          if (element && !attached) {
              element.addEventListener(type, listener, supportsPassive ? { capture: capture, passive: passive } : capture);
              attached = true;
          }
      };
      var remove = function () {
          var element = vue_1.unref(target);
          if (element && attached) {
              element.removeEventListener(type, listener, capture);
              attached = false;
          }
      };
      vue_1.onUnmounted(remove);
      vue_1.onDeactivated(remove);
      onMountedOrActivated_1.onMountedOrActivated(add);
  }
  exports.useEventListener = useEventListener;
  