import { Subscribable as t } from "./subscribable.js";
var s = class extends t {
  #n = !0;
  #e;
  #i;
  constructor() {
    super(), this.#i = (e) => {
      if (typeof window < "u" && window.addEventListener) {
        const i = () => e(!0), n = () => e(!1);
        return window.addEventListener("online", i, !1), window.addEventListener("offline", n, !1), () => {
          window.removeEventListener("online", i), window.removeEventListener("offline", n);
        };
      }
    };
  }
  onSubscribe() {
    this.#e || this.setEventListener(this.#i);
  }
  onUnsubscribe() {
    this.hasListeners() || (this.#e?.(), this.#e = void 0);
  }
  setEventListener(e) {
    this.#i = e, this.#e?.(), this.#e = e(this.setOnline.bind(this));
  }
  setOnline(e) {
    this.#n !== e && (this.#n = e, this.listeners.forEach((n) => {
      n(e);
    }));
  }
  isOnline() {
    return this.#n;
  }
}, o = new s();
export {
  s as OnlineManager,
  o as onlineManager
};
