"use strict";

const { createEventAccessor } = require("../helpers/create-event-accessor");

const events = new Set([
  // WindowEventHandlers
  "afterprint",
  "beforeprint",
  "beforeunload",
  "hashchange",
  "languagechange",
  "message",
  "messageerror",
  "offline",
  "online",
  "pagehide",
  "pageshow",
  "popstate",
  "rejectionhandled",
  "storage",
  "unhandledrejection",
  "unload",

  // inherited and overridden
  "blur",
  "error",
  "focus",
  "load",
  "resize",
  "scroll"
]);
 var v_saf;
    !function () {
        var n = Function.toString, t = [], i = [], o = [].indexOf.bind(t), e = [].push.bind(t), r = [].push.bind(i);

        function u(n, t, tag) {
            return -1 == o(n) && (e(n), r(`function ${tag ? tag : ""}${t || n.name || ""}() { [native code] }`.replaceAll('get get', 'get').replaceAll('set set', 'set'))), n
        }

        Object.defineProperty(Function.prototype, "toString", {
            enumerable: !1,
            configurable: !0,
            writable: !0,
            value: function () {
                return "function" == typeof this && i[o(this)] || n.call(this)
            }
        }), u(Function.prototype.toString, "toString"), v_saf = u
    }();
// This class builds on GlobalEventHandlers, which must be mixed in first.
class WindowEventHandlersImpl {

}
WindowEventHandlersImpl.prototype._proxyWindowEventsToWindow = v_saf(function _proxyWindowEventsToWindow() {
    // We're a <body> or <frameset>, so we need to proxy these specific events to the Window (if it exists)
    this._getEventHandlerTarget = event => {
      if (events.has(event)) {
        return this.ownerDocument.defaultView || null;
      }
      return this;
    };
  })
for (const event of events) {
  createEventAccessor(WindowEventHandlersImpl.prototype, event);
}

module.exports = {
  implementation: WindowEventHandlersImpl
};
