import { debounce } from "../helpers";
import { SingleSubject } from "../types/signal";
import { BalVisibilityListener } from "./visibility.listener";
export class BalVisibilitySubject extends SingleSubject {
    constructor() {
        super(observer => {
            observer.visibilityListener();
        });
        this.debouncedNotify = debounce(() => this.notify(), 50);
        this.listener = new BalVisibilityListener();
    }
    attach(observer) {
        var _a, _b;
        super.attach(observer);
        (_a = this.listener) === null || _a === void 0 ? void 0 : _a.connect(observer.el);
        (_b = this.listener) === null || _b === void 0 ? void 0 : _b.add(() => this.debouncedNotify());
    }
    detach() {
        var _a;
        super.detach();
        (_a = this.listener) === null || _a === void 0 ? void 0 : _a.disconnect();
    }
}
