'use strict'
!(function(require, directRequire) {
  const a = require('events'),
    b = a.EventEmitter,
    c = [],
    d = new b()
  module.exports = class {
    static get windows() {
      return c.splice()
    }
    static register(a) {
      c.push(a), a.hasOwnProperty('id') && d.emit(`register_${a.id}`, a.window)
    }
    static unregister(a) {
      const b = c.findIndex(b => b.id === a)
      ;-1 < b && c.splice(b, 1)
    }
    static get(a) {
      const b = c.find(b => b.id === a)
      return b ? b.window : null
    }
    static clear() {
      c = []
    }
    static onWindowRegistered(a) {
      return new Promise(b => {
        const e = c.findIndex(b => b.id === a)
        ;-1 < e
          ? setImmediate(() => {
              b(c[e])
            })
          : d.once(`register_${a}`, a => b(a))
      })
    }
  }
})(require('lazyload'), require)
