var u = (i) => {
  throw TypeError(i);
};
var d = (i, s, e) => s.has(i) || u("Cannot " + e);
var t = (i, s, e) => (d(i, s, "read from private field"), e ? e.call(i) : s.get(i)), a = (i, s, e) => s.has(i) ? u("Cannot add the same private member more than once") : s instanceof WeakSet ? s.add(i) : s.set(i, e), r = (i, s, e, c) => (d(i, s, "write to private field"), c ? c.call(i, e) : s.set(i, e), e);
import { Subscribable as b } from "./subscribable.js";
import { isServer as v } from "./utils.js";
var o, n, h, l, f = (l = class extends b {
  constructor() {
    super();
    a(this, o);
    a(this, n);
    a(this, h);
    r(this, h, (s) => {
      if (!v && window.addEventListener) {
        const e = () => s();
        return window.addEventListener("visibilitychange", e, !1), () => {
          window.removeEventListener("visibilitychange", e);
        };
      }
    });
  }
  onSubscribe() {
    t(this, n) || this.setEventListener(t(this, h));
  }
  onUnsubscribe() {
    var s;
    this.hasListeners() || ((s = t(this, n)) == null || s.call(this), r(this, n, void 0));
  }
  setEventListener(s) {
    var e;
    r(this, h, s), (e = t(this, n)) == null || e.call(this), r(this, n, s((c) => {
      typeof c == "boolean" ? this.setFocused(c) : this.onFocus();
    }));
  }
  setFocused(s) {
    t(this, o) !== s && (r(this, o, s), this.onFocus());
  }
  onFocus() {
    const s = this.isFocused();
    this.listeners.forEach((e) => {
      e(s);
    });
  }
  isFocused() {
    var s;
    return typeof t(this, o) == "boolean" ? t(this, o) : ((s = globalThis.document) == null ? void 0 : s.visibilityState) !== "hidden";
  }
}, o = new WeakMap(), n = new WeakMap(), h = new WeakMap(), l), w = new f();
export {
  f as FocusManager,
  w as focusManager
};
//# sourceMappingURL=focusManager.js.map
