"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var AbstractDetailPage_1 = require("./pages/AbstractDetailPage");
var placeholder_1 = require("./pages/placeholder/placeholder");
var MasterDetailNavService = /** @class */ (function () {
    function MasterDetailNavService() {
        this._isViewChanging = false;
    }
    Object.defineProperty(MasterDetailNavService.prototype, "masterNav", {
        get: function () {
            return this._masterNav;
        },
        set: function (nav) {
            this._masterNav = nav;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MasterDetailNavService.prototype, "detailNav", {
        get: function () {
            return this._detailNav;
        },
        set: function (nav) {
            this._detailNav = nav;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MasterDetailNavService.prototype, "parentNav", {
        get: function () {
            return this._parentNav;
        },
        set: function (nav) {
            this._parentNav = nav;
        },
        enumerable: true,
        configurable: true
    });
    MasterDetailNavService.prototype.pushDetail = function (page, params) {
        if (this.useParentNav) {
            this.parentNav.push(page, params);
        }
        else {
            this.detailNav.push(page, params);
        }
    };
    MasterDetailNavService.prototype.pushMaster = function (page, params) {
        this.masterNav.push(page, params);
    };
    MasterDetailNavService.prototype.onDetailVisibilityChanged = function (isDetailVisible, parentNav) {
        this._isDetailVisible = isDetailVisible;
        if (this.masterNav && this.detailNav) {
            isDetailVisible ? this.showDetail(parentNav) : this.hideDetail(parentNav);
        }
    };
    MasterDetailNavService.prototype.showDetail = function (parentNav) {
        var _this = this;
        if (this._isViewChanging) {
            return Promise.resolve();
        }
        this._isViewChanging = true;
        // assumes that the master detail is at top
        return parentNav.popToRoot()
            .then(function () {
            _this._isViewChanging = false;
            _this.useParentNav = false;
        });
    };
    MasterDetailNavService.prototype.hideDetail = function (parentNav) {
        var _this = this;
        if (this._isViewChanging) {
            return Promise.resolve();
        }
        this._isViewChanging = true;
        var activeMasterView = this.masterNav.getActive();
        var activeDetailView = this.detailNav.getActive();
        if (activeDetailView.component.prototype instanceof AbstractDetailPage_1.AbstractDetailPage) {
            return parentNav.push(activeMasterView.component, activeMasterView.data)
                .then(function () { return parentNav.push(activeDetailView.component, activeDetailView.data); })
                .then(function () {
                _this.useParentNav = true;
                _this._isViewChanging = false;
            });
        }
        else if (activeDetailView.component.prototype instanceof placeholder_1.PlaceholderPage) {
            return parentNav.push(activeMasterView.component, activeMasterView.data)
                .then(function () {
                _this.useParentNav = true;
                _this._isViewChanging = false;
            });
        }
        else {
            this.useParentNav = true;
            this._isViewChanging = false;
        }
    };
    return MasterDetailNavService;
}());
exports.MasterDetailNavService = MasterDetailNavService;
//# sourceMappingURL=master-detail-nav.service.js.map