import { CommonModule } from '@angular/common';
import { TemplateRef, ɵɵdirectiveInject, ViewContainerRef, ɵɵdefineDirective, ɵɵNgOnChangesFeature, ɵsetClassMetadata, Directive, Input, ɵɵdefineNgModule, ɵɵdefineInjector, ɵɵsetNgModuleScope, NgModule } from '@angular/core';
import { __values } from 'tslib';

var NzStringTemplateOutletDirective = /** @class */ (function () {
    function NzStringTemplateOutletDirective(viewContainer, templateRef) {
        this.viewContainer = viewContainer;
        this.templateRef = templateRef;
        this.embeddedViewRef = null;
        this.nzStringTemplateOutletContext = null;
        this.nzStringTemplateOutlet = null;
    }
    NzStringTemplateOutletDirective.prototype.recreateView = function () {
        this.viewContainer.clear();
        var isTemplateRef = this.nzStringTemplateOutlet instanceof TemplateRef;
        var templateRef = (isTemplateRef ? this.nzStringTemplateOutlet : this.templateRef);
        this.embeddedViewRef = this.viewContainer.createEmbeddedView(templateRef, this.nzStringTemplateOutletContext);
    };
    NzStringTemplateOutletDirective.prototype.updateContext = function () {
        var e_1, _a;
        var newCtx = this.nzStringTemplateOutletContext;
        var oldCtx = this.embeddedViewRef.context;
        if (newCtx) {
            try {
                for (var _b = __values(Object.keys(newCtx)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var propName = _c.value;
                    oldCtx[propName] = newCtx[propName];
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_1) throw e_1.error; }
            }
        }
    };
    NzStringTemplateOutletDirective.prototype.ngOnChanges = function (changes) {
        var shouldRecreateView = function (ctxChanges) {
            var nzStringTemplateOutletContext = ctxChanges.nzStringTemplateOutletContext, nzStringTemplateOutlet = ctxChanges.nzStringTemplateOutlet;
            var shouldOutletRecreate = false;
            if (nzStringTemplateOutlet) {
                if (nzStringTemplateOutlet.firstChange) {
                    shouldOutletRecreate = true;
                }
                else {
                    var isPreviousOutletTemplate = nzStringTemplateOutlet.previousValue instanceof TemplateRef;
                    var isCurrentOutletTemplate = nzStringTemplateOutlet.currentValue instanceof TemplateRef;
                    shouldOutletRecreate = isPreviousOutletTemplate || isCurrentOutletTemplate;
                }
            }
            var hasContextShapeChanged = function (ctxChange) {
                var e_2, _a;
                var prevCtxKeys = Object.keys(ctxChange.previousValue || {});
                var currCtxKeys = Object.keys(ctxChange.currentValue || {});
                if (prevCtxKeys.length === currCtxKeys.length) {
                    try {
                        for (var currCtxKeys_1 = __values(currCtxKeys), currCtxKeys_1_1 = currCtxKeys_1.next(); !currCtxKeys_1_1.done; currCtxKeys_1_1 = currCtxKeys_1.next()) {
                            var propName = currCtxKeys_1_1.value;
                            if (prevCtxKeys.indexOf(propName) === -1) {
                                return true;
                            }
                        }
                    }
                    catch (e_2_1) { e_2 = { error: e_2_1 }; }
                    finally {
                        try {
                            if (currCtxKeys_1_1 && !currCtxKeys_1_1.done && (_a = currCtxKeys_1.return)) _a.call(currCtxKeys_1);
                        }
                        finally { if (e_2) throw e_2.error; }
                    }
                    return false;
                }
                else {
                    return true;
                }
            };
            var shouldContextRecreate = nzStringTemplateOutletContext && hasContextShapeChanged(nzStringTemplateOutletContext);
            return shouldContextRecreate || shouldOutletRecreate;
        };
        var recreateView = shouldRecreateView(changes);
        if (recreateView) {
            /** recreate view when context shape or outlet change **/
            this.recreateView();
        }
        else {
            /** update context **/
            this.updateContext();
        }
    };
    /** @nocollapse */ NzStringTemplateOutletDirective.ɵfac = function NzStringTemplateOutletDirective_Factory(t) { return new (t || NzStringTemplateOutletDirective)(ɵɵdirectiveInject(ViewContainerRef), ɵɵdirectiveInject(TemplateRef)); };
    /** @nocollapse */ NzStringTemplateOutletDirective.ɵdir = ɵɵdefineDirective({ type: NzStringTemplateOutletDirective, selectors: [["", "nzStringTemplateOutlet", ""]], inputs: { nzStringTemplateOutletContext: "nzStringTemplateOutletContext", nzStringTemplateOutlet: "nzStringTemplateOutlet" }, exportAs: ["nzStringTemplateOutlet"], features: [ɵɵNgOnChangesFeature] });
    return NzStringTemplateOutletDirective;
}());
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzStringTemplateOutletDirective, [{
        type: Directive,
        args: [{
                selector: '[nzStringTemplateOutlet]',
                exportAs: 'nzStringTemplateOutlet'
            }]
    }], function () { return [{ type: ViewContainerRef }, { type: TemplateRef }]; }, { nzStringTemplateOutletContext: [{
            type: Input
        }], nzStringTemplateOutlet: [{
            type: Input
        }] }); })();

/**
 * @license
 * Copyright Alibaba.com All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */
var NzOutletModule = /** @class */ (function () {
    function NzOutletModule() {
    }
    /** @nocollapse */ NzOutletModule.ɵmod = ɵɵdefineNgModule({ type: NzOutletModule });
    /** @nocollapse */ NzOutletModule.ɵinj = ɵɵdefineInjector({ factory: function NzOutletModule_Factory(t) { return new (t || NzOutletModule)(); }, imports: [[CommonModule]] });
    return NzOutletModule;
}());
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && ɵɵsetNgModuleScope(NzOutletModule, { declarations: [NzStringTemplateOutletDirective], imports: [CommonModule], exports: [NzStringTemplateOutletDirective] }); })();
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzOutletModule, [{
        type: NgModule,
        args: [{
                imports: [CommonModule],
                exports: [NzStringTemplateOutletDirective],
                declarations: [NzStringTemplateOutletDirective]
            }]
    }], null, null); })();

/**
 * @license
 * Copyright Alibaba.com All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */

/**
 * Generated bundle index. Do not edit.
 */

export { NzOutletModule, NzStringTemplateOutletDirective };
//# sourceMappingURL=ng-zorro-antd-core-outlet.js.map
