// #region Imports
import { Signal } from '../Index';
// #endregion
/**
 * A abstract view presenter.
 *
 * @public
 * @abstract
 */
export class ViewPresenter {
    // #region Fields
    _initialized;
    _disposed;
    _isLoading;
    _activeOperations;
    // #endregion
    // #region Ctor
    /**
    * Constructs a new instance of the `ViewPresenter` class.
    *
    * @protected
    */
    constructor() {
        this._initialized = Signal.from(false);
        this._disposed = Signal.from(false);
        this._isLoading = Signal.from(false);
        this._activeOperations = 0;
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `disposed` property.
     *
     * @public
     * @readonly
     */
    get disposed() {
        return this._disposed;
    }
    /**
     * Returns the `initialized` property.
     *
     * @public
     */
    get initialized() {
        return this._initialized;
    }
    /**
     * Returns the `isLoading` property.
     *
     * @public
     * @readonly
     */
    get isLoading() {
        return this._isLoading;
    }
    // #endregion
    // #region Methods
    /**
    * Called before the view first displays the data-bound properties and sets the view's input properties.
    *
    * @public
    * @virtual
    */
    initialize() {
        this._initialized.set(true);
    }
    /**
    * Called before the view will be destroyed.
    * Unsubscribe Observables and detach event handlers to avoid memory leaks.
    *
    * @public
    * @virtual
    */
    dispose() {
        this._disposed.set(true);
        this._isLoading.set(false);
    }
    /**
     * @protected
     */
    loading(value) {
        if (value) {
            this._activeOperations++;
        }
        else if (this._activeOperations > 0) {
            this._activeOperations--;
        }
        if (this._activeOperations === 0) {
            this._isLoading.set(false);
        }
        else {
            this._isLoading.set(true);
        }
    }
}
//# sourceMappingURL=ViewPresenter.js.map