import { __assign } from "tslib";
/**
 * @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
 */
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { isPromise } from 'ng-zorro-antd/core';
import { NzI18nService } from 'ng-zorro-antd/i18n';
import { NzModalRef } from './modal-ref';
import { ModalOptions } from './modal-types';
import * as i0 from "@angular/core";
import * as i1 from "ng-zorro-antd/i18n";
import * as i2 from "./modal-types";
import * as i3 from "@angular/common";
import * as i4 from "ng-zorro-antd/core";
import * as i5 from "ng-zorro-antd/button";
import * as i6 from "ng-zorro-antd/core/transition-patch";
var _c0 = ["nz-modal-footer", ""];
function NzModalFooterComponent_ng_container_0_ng_container_1_div_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "div", 5);
} if (rf & 2) {
    var ctx_r1985 = i0.ɵɵnextContext(3);
    i0.ɵɵproperty("innerHTML", ctx_r1985.config.nzTitle, i0.ɵɵsanitizeHtml);
} }
function NzModalFooterComponent_ng_container_0_ng_container_1_ng_container_2_button_1_Template(rf, ctx) { if (rf & 1) {
    var _r1990 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 7);
    i0.ɵɵlistener("click", function NzModalFooterComponent_ng_container_0_ng_container_1_ng_container_2_button_1_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r1990); var button_r1988 = ctx.$implicit; var ctx_r1989 = i0.ɵɵnextContext(4); return ctx_r1989.onButtonClick(button_r1988); });
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var button_r1988 = ctx.$implicit;
    var ctx_r1987 = i0.ɵɵnextContext(4);
    i0.ɵɵproperty("hidden", !ctx_r1987.getButtonCallableProp(button_r1988, "show"))("nzLoading", ctx_r1987.getButtonCallableProp(button_r1988, "loading"))("disabled", ctx_r1987.getButtonCallableProp(button_r1988, "disabled"))("nzType", button_r1988.type)("nzShape", button_r1988.shape)("nzSize", button_r1988.size)("nzGhost", button_r1988.ghost);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" ", button_r1988.label, " ");
} }
function NzModalFooterComponent_ng_container_0_ng_container_1_ng_container_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, NzModalFooterComponent_ng_container_0_ng_container_1_ng_container_2_button_1_Template, 2, 8, "button", 6);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    var ctx_r1986 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngForOf", ctx_r1986.buttons);
} }
function NzModalFooterComponent_ng_container_0_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, NzModalFooterComponent_ng_container_0_ng_container_1_div_1_Template, 1, 1, "div", 3);
    i0.ɵɵtemplate(2, NzModalFooterComponent_ng_container_0_ng_container_1_ng_container_2_Template, 2, 1, "ng-container", 4);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    var ctx_r1984 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r1984.buttonsFooter);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r1984.buttonsFooter);
} }
function NzModalFooterComponent_ng_container_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, NzModalFooterComponent_ng_container_0_ng_container_1_Template, 3, 2, "ng-container", 2);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    var ctx_r1981 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("nzStringTemplateOutlet", ctx_r1981.config.nzFooter);
} }
function NzModalFooterComponent_ng_template_1_button_0_Template(rf, ctx) { if (rf & 1) {
    var _r1994 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 10);
    i0.ɵɵlistener("click", function NzModalFooterComponent_ng_template_1_button_0_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r1994); var ctx_r1993 = i0.ɵɵnextContext(2); return ctx_r1993.onCancel(); });
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var ctx_r1991 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("nzLoading", ctx_r1991.config.nzCancelLoading)("disabled", ctx_r1991.config.nzCancelDisabled);
    i0.ɵɵattribute("cdkFocusInitial", ctx_r1991.config.nzAutofocus === "cancel");
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" ", ctx_r1991.config.nzCancelText || ctx_r1991.locale.cancelText, " ");
} }
function NzModalFooterComponent_ng_template_1_button_1_Template(rf, ctx) { if (rf & 1) {
    var _r1996 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 11);
    i0.ɵɵlistener("click", function NzModalFooterComponent_ng_template_1_button_1_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r1996); var ctx_r1995 = i0.ɵɵnextContext(2); return ctx_r1995.onOk(); });
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var ctx_r1992 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("nzType", ctx_r1992.config.nzOkType)("nzLoading", ctx_r1992.config.nzOkLoading)("disabled", ctx_r1992.config.nzOkDisabled);
    i0.ɵɵattribute("cdkFocusInitial", ctx_r1992.config.nzAutofocus === "ok");
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" ", ctx_r1992.config.nzOkText || ctx_r1992.locale.okText, " ");
} }
function NzModalFooterComponent_ng_template_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵtemplate(0, NzModalFooterComponent_ng_template_1_button_0_Template, 2, 4, "button", 8);
    i0.ɵɵtemplate(1, NzModalFooterComponent_ng_template_1_button_1_Template, 2, 5, "button", 9);
} if (rf & 2) {
    var ctx_r1983 = i0.ɵɵnextContext();
    i0.ɵɵproperty("ngIf", ctx_r1983.config.nzCancelText !== null);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r1983.config.nzOkText !== null);
} }
var NzModalFooterComponent = /** @class */ (function () {
    function NzModalFooterComponent(i18n, config) {
        var _this = this;
        this.i18n = i18n;
        this.config = config;
        this.buttonsFooter = false;
        this.buttons = [];
        this.locale = {};
        this.cancelTriggered = new EventEmitter();
        this.okTriggered = new EventEmitter();
        this.destroy$ = new Subject();
        if (Array.isArray(config.nzFooter)) {
            this.buttonsFooter = true;
            this.buttons = config.nzFooter.map(mergeDefaultOption);
        }
        this.i18n.localeChange.pipe(takeUntil(this.destroy$)).subscribe(function () {
            _this.locale = _this.i18n.getLocaleData('Modal');
        });
    }
    NzModalFooterComponent.prototype.onCancel = function () {
        this.cancelTriggered.emit();
    };
    NzModalFooterComponent.prototype.onOk = function () {
        this.okTriggered.emit();
    };
    /**
     * Returns the value of the specified key.
     * If it is a function, run and return the return value of the function.
     * @deprecated Not support use function type.
     * @breaking-change 10.0.0
     */
    NzModalFooterComponent.prototype.getButtonCallableProp = function (options, prop) {
        var value = options[prop];
        var componentInstance = this.modalRef.getContentComponent();
        return typeof value === 'function' ? value.apply(options, componentInstance && [componentInstance]) : value;
    };
    /**
     * Run function based on the type and set its `loading` prop if needed.
     * @deprecated Should be set options' value by the user, not library.
     * @breaking-change 10.0.0
     */
    NzModalFooterComponent.prototype.onButtonClick = function (options) {
        var loading = this.getButtonCallableProp(options, 'loading');
        if (!loading) {
            var result = this.getButtonCallableProp(options, 'onClick');
            if (options.autoLoading && isPromise(result)) {
                options.loading = true;
                result.then(function () { return (options.loading = false); }).catch(function () { return (options.loading = false); });
            }
        }
    };
    NzModalFooterComponent.prototype.ngOnDestroy = function () {
        this.destroy$.next();
        this.destroy$.complete();
    };
    /** @nocollapse */ NzModalFooterComponent.ɵfac = function NzModalFooterComponent_Factory(t) { return new (t || NzModalFooterComponent)(i0.ɵɵdirectiveInject(i1.NzI18nService), i0.ɵɵdirectiveInject(i2.ModalOptions)); };
    /** @nocollapse */ NzModalFooterComponent.ɵcmp = i0.ɵɵdefineComponent({ type: NzModalFooterComponent, selectors: [["div", "nz-modal-footer", ""]], hostAttrs: [1, "ant-modal-footer"], inputs: { modalRef: "modalRef" }, outputs: { cancelTriggered: "cancelTriggered", okTriggered: "okTriggered" }, exportAs: ["NzModalFooterBuiltin"], attrs: _c0, decls: 3, vars: 2, consts: [[4, "ngIf", "ngIfElse"], ["defaultFooterButtons", ""], [4, "nzStringTemplateOutlet"], [3, "innerHTML", 4, "ngIf"], [4, "ngIf"], [3, "innerHTML"], ["nz-button", "", 3, "hidden", "nzLoading", "disabled", "nzType", "nzShape", "nzSize", "nzGhost", "click", 4, "ngFor", "ngForOf"], ["nz-button", "", 3, "hidden", "nzLoading", "disabled", "nzType", "nzShape", "nzSize", "nzGhost", "click"], ["nz-button", "", 3, "nzLoading", "disabled", "click", 4, "ngIf"], ["nz-button", "", 3, "nzType", "nzLoading", "disabled", "click", 4, "ngIf"], ["nz-button", "", 3, "nzLoading", "disabled", "click"], ["nz-button", "", 3, "nzType", "nzLoading", "disabled", "click"]], template: function NzModalFooterComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵtemplate(0, NzModalFooterComponent_ng_container_0_Template, 2, 1, "ng-container", 0);
            i0.ɵɵtemplate(1, NzModalFooterComponent_ng_template_1_Template, 2, 2, "ng-template", null, 1, i0.ɵɵtemplateRefExtractor);
        } if (rf & 2) {
            var _r1982 = i0.ɵɵreference(2);
            i0.ɵɵproperty("ngIf", ctx.config.nzFooter)("ngIfElse", _r1982);
        } }, directives: [i3.NgIf, i4.NzStringTemplateOutletDirective, i3.NgForOf, i5.NzButtonComponent, i4.NzWaveDirective, i6.ɵNzTransitionPatchDirective], encapsulation: 2 });
    return NzModalFooterComponent;
}());
export { NzModalFooterComponent };
/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(NzModalFooterComponent, [{
        type: Component,
        args: [{
                selector: 'div[nz-modal-footer]',
                exportAs: 'NzModalFooterBuiltin',
                template: "\n    <ng-container *ngIf=\"config.nzFooter; else defaultFooterButtons\">\n      <ng-container *nzStringTemplateOutlet=\"config.nzFooter\">\n        <div *ngIf=\"!buttonsFooter\" [innerHTML]=\"config.nzTitle\"></div>\n        <ng-container *ngIf=\"buttonsFooter\">\n          <button\n            *ngFor=\"let button of buttons\"\n            nz-button\n            (click)=\"onButtonClick(button)\"\n            [hidden]=\"!getButtonCallableProp(button, 'show')\"\n            [nzLoading]=\"getButtonCallableProp(button, 'loading')\"\n            [disabled]=\"getButtonCallableProp(button, 'disabled')\"\n            [nzType]=\"button.type\"\n            [nzShape]=\"button.shape\"\n            [nzSize]=\"button.size\"\n            [nzGhost]=\"button.ghost\"\n          >\n            {{ button.label }}\n          </button>\n        </ng-container>\n      </ng-container>\n    </ng-container>\n    <ng-template #defaultFooterButtons>\n      <button\n        *ngIf=\"config.nzCancelText !== null\"\n        [attr.cdkFocusInitial]=\"config.nzAutofocus === 'cancel'\"\n        nz-button\n        (click)=\"onCancel()\"\n        [nzLoading]=\"config.nzCancelLoading\"\n        [disabled]=\"config.nzCancelDisabled\"\n      >\n        {{ config.nzCancelText || locale.cancelText }}\n      </button>\n      <button\n        *ngIf=\"config.nzOkText !== null\"\n        [attr.cdkFocusInitial]=\"config.nzAutofocus === 'ok'\"\n        nz-button\n        [nzType]=\"config.nzOkType\"\n        (click)=\"onOk()\"\n        [nzLoading]=\"config.nzOkLoading\"\n        [disabled]=\"config.nzOkDisabled\"\n      >\n        {{ config.nzOkText || locale.okText }}\n      </button>\n    </ng-template>\n  ",
                host: {
                    class: 'ant-modal-footer'
                },
                changeDetection: ChangeDetectionStrategy.Default
            }]
    }], function () { return [{ type: i1.NzI18nService }, { type: i2.ModalOptions }]; }, { cancelTriggered: [{
            type: Output
        }], okTriggered: [{
            type: Output
        }], modalRef: [{
            type: Input
        }] }); })();
function mergeDefaultOption(options) {
    return __assign({ type: null, size: 'default', autoLoading: true, show: true, loading: false, disabled: false }, options);
}
//# sourceMappingURL=data:application/json;base64, 