import "core-js/modules/es.array.for-each.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/esnext.iterator.constructor.js";
import "core-js/modules/esnext.iterator.for-each.js";
import "core-js/modules/web.dom-collections.for-each.js";
export var scopedProxyEventListener = function scopedProxyEventListener(_ref) {
  var windowProxy = _ref.windowProxy,
    listener = _ref.listener,
    eventName = _ref.eventName,
    el = _ref.el,
    listenerList = _ref.listenerList;
  var windowObj = windowProxy !== null && windowProxy !== void 0 ? windowProxy : window;
  var propaHandler = function propaHandler(e) {
    // need to call back other clickAnywhere
    // before e.stopPropagation,
    // if there are more than one
    listenerList.forEach(function (ocb) {
      if (ocb !== listener) {
        ocb();
      }
    });
    e.stopPropagation();
  };
  var callbackHandler = function callbackHandler() {
    listener();
  };
  el.addEventListener(eventName, propaHandler);
  windowObj.addEventListener(eventName, callbackHandler);
  listenerList.add(listener);
  return function () {
    el.removeEventListener(eventName, propaHandler);
    windowObj.removeEventListener(eventName, callbackHandler);
    listenerList["delete"](listener);
  };
};