import { ReplaySubject, Subject } from 'rxjs';
import { ElWindowState } from './window.options';
/**
 * The `ElWindowRef` helps to manipulate window after it was created.
 * The window can be dismissed by using `close` method of the windowRef.
 * You can access rendered component as `componentRef` property of the windowRef.
 */
var ElWindowRef = /** @class */ (function () {
    function ElWindowRef(config) {
        this.config = config;
        this.stateChange$ = new ReplaySubject(1);
        this._closed = false;
        this.closed$ = new Subject();
        this.state = config.initialState;
    }
    Object.defineProperty(ElWindowRef.prototype, "state", {
        /**
         * Current window state.
         */
        get: function () {
            return this.stateValue;
        },
        set: function (newState) {
            if (newState && this.stateValue !== newState) {
                this.prevStateValue = this.state;
                this.stateValue = newState;
                this.stateChange$.next({ oldState: this.prevStateValue, newState: newState });
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ElWindowRef.prototype, "stateChange", {
        /**
         * Emits when window state change.
         */
        get: function () {
            return this.stateChange$.asObservable();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ElWindowRef.prototype, "onClose", {
        /**
         * Emits when window was closed.
         */
        get: function () {
            return this.closed$.asObservable();
        },
        enumerable: true,
        configurable: true
    });
    /**
     * Minimize window.
     */
    ElWindowRef.prototype.minimize = function () {
        this.state = ElWindowState.MINIMIZED;
    };
    /**
     * Maximize window.
     */
    ElWindowRef.prototype.maximize = function () {
        this.state = ElWindowState.MAXIMIZED;
    };
    /**
     * Set window on top.
     */
    ElWindowRef.prototype.fullScreen = function () {
        this.state = ElWindowState.FULL_SCREEN;
    };
    ElWindowRef.prototype.toPreviousState = function () {
        this.state = this.prevStateValue;
    };
    /**
     * Closes window.
     * */
    ElWindowRef.prototype.close = function () {
        if (this._closed) {
            return;
        }
        this._closed = true;
        this.componentRef.destroy();
        this.stateChange$.complete();
        this.closed$.next();
        this.closed$.complete();
    };
    return ElWindowRef;
}());
export { ElWindowRef };
//# sourceMappingURL=window-ref.js.map