'use strict';

var breakpoints_subject = require('./breakpoints.subject-CXJYXMpo.js');
var listener = require('./listener-DspXpqzY.js');
var browser = require('./browser-BwmkTmm8.js');

class BalWindowResizeSubject extends listener.SingleSubject {
    constructor() {
        super((observer, _data) => {
            observer.windowResizeListener();
        });
        this.listener = new breakpoints_subject.BalWindowResizeListener();
    }
    attach(observer) {
        super.attach(observer);
        if (browser.balBrowser.hasWindow) {
            this.listener.connect(window);
            this.listener.add(() => super.notify());
        }
    }
    detach() {
        super.detach();
        this.listener.disconnect();
    }
}
new BalWindowResizeSubject();

function ListenToWindowResize() {
    return function (target, _propertyKey, _descriptor) {
        const { connectedCallback, disconnectedCallback } = target;
        target.connectedCallback = function () {
            if (!this._balWindowResizeSubject) {
                this._balWindowResizeSubject = new BalWindowResizeSubject();
                this._balWindowResizeSubject.attach(this);
            }
            return connectedCallback && connectedCallback.call(this);
        };
        target.disconnectedCallback = function () {
            if (this._balWindowResizeSubject) {
                this._balWindowResizeSubject.detach();
                this._balWindowResizeSubject = undefined;
            }
            return disconnectedCallback && disconnectedCallback.call(this);
        };
    };
}

exports.ListenToWindowResize = ListenToWindowResize;
