import { addEventListener, removeEventListener, debounce } from "../helpers";
import { BalWindowResizeHandler } from "./window-resize.handler";
import { ListenerAbstract } from "../types/listener";
export class BalWindowResizeListener extends ListenerAbstract {
    constructor() {
        super(...arguments);
        this.resizeHandler = new BalWindowResizeHandler({ onlyListenToWidthChanges: true });
        this.debouncedNotify = debounce(() => this.notify(), 100);
        this.notify = async () => {
            if (await this.resizeHandler.hasResized()) {
                super.notify(undefined);
            }
        };
    }
    connect(el) {
        super.connect(el);
        if (this.el) {
            addEventListener(this.el, 'resize', this.debouncedNotify, { passive: true });
        }
    }
    disconnect() {
        super.disconnect();
        if (this.el) {
            removeEventListener(this.el, 'resize', this.debouncedNotify);
        }
    }
}
