/**
 * @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, ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core';
import { NzI18nService } from 'ng-zorro-antd/i18n';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import * as i0 from "@angular/core";
import * as i1 from "ng-zorro-antd/i18n";
import * as i2 from "@angular/common";
import * as i3 from "./filter-trigger.component";
import * as i4 from "ng-zorro-antd/icon";
import * as i5 from "ng-zorro-antd/dropdown";
import * as i6 from "ng-zorro-antd/menu";
import * as i7 from "ng-zorro-antd/radio";
import * as i8 from "@angular/forms";
import * as i9 from "ng-zorro-antd/checkbox";
function NzTableFilterComponent_ng_template_1_Template(rf, ctx) { }
function NzTableFilterComponent_ng_container_2_li_8_label_1_Template(rf, ctx) { if (rf & 1) {
    var _r2946 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "label", 16);
    i0.ɵɵlistener("ngModelChange", function NzTableFilterComponent_ng_container_2_li_8_label_1_Template_label_ngModelChange_0_listener() { i0.ɵɵrestoreView(_r2946); var f_r2941 = i0.ɵɵnextContext().$implicit; var ctx_r2944 = i0.ɵɵnextContext(2); return ctx_r2944.check(f_r2941); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var f_r2941 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵproperty("ngModel", f_r2941.checked);
} }
function NzTableFilterComponent_ng_container_2_li_8_label_2_Template(rf, ctx) { if (rf & 1) {
    var _r2950 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "label", 17);
    i0.ɵɵlistener("ngModelChange", function NzTableFilterComponent_ng_container_2_li_8_label_2_Template_label_ngModelChange_0_listener() { i0.ɵɵrestoreView(_r2950); var f_r2941 = i0.ɵɵnextContext().$implicit; var ctx_r2948 = i0.ɵɵnextContext(2); return ctx_r2948.check(f_r2941); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var f_r2941 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵproperty("ngModel", f_r2941.checked);
} }
function NzTableFilterComponent_ng_container_2_li_8_Template(rf, ctx) { if (rf & 1) {
    var _r2953 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "li", 13);
    i0.ɵɵlistener("click", function NzTableFilterComponent_ng_container_2_li_8_Template_li_click_0_listener() { i0.ɵɵrestoreView(_r2953); var f_r2941 = ctx.$implicit; var ctx_r2952 = i0.ɵɵnextContext(2); return ctx_r2952.check(f_r2941); });
    i0.ɵɵtemplate(1, NzTableFilterComponent_ng_container_2_li_8_label_1_Template, 1, 1, "label", 14);
    i0.ɵɵtemplate(2, NzTableFilterComponent_ng_container_2_li_8_label_2_Template, 1, 1, "label", 15);
    i0.ɵɵelementStart(3, "span");
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var f_r2941 = ctx.$implicit;
    var ctx_r2940 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r2940.filterMultiple);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r2940.filterMultiple);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(f_r2941.text);
} }
function NzTableFilterComponent_ng_container_2_Template(rf, ctx) { if (rf & 1) {
    var _r2955 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "nz-filter-trigger", 3, 4);
    i0.ɵɵlistener("nzVisibleChange", function NzTableFilterComponent_ng_container_2_Template_nz_filter_trigger_nzVisibleChange_1_listener($event) { i0.ɵɵrestoreView(_r2955); var ctx_r2954 = i0.ɵɵnextContext(); return ctx_r2954.onVisibleChange($event); });
    i0.ɵɵelement(3, "i", 5);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "nz-dropdown-menu", null, 6);
    i0.ɵɵelementStart(6, "div", 7);
    i0.ɵɵelementStart(7, "ul", 8);
    i0.ɵɵtemplate(8, NzTableFilterComponent_ng_container_2_li_8_Template, 5, 3, "li", 9);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(9, "div", 10);
    i0.ɵɵelementStart(10, "a", 11);
    i0.ɵɵlistener("click", function NzTableFilterComponent_ng_container_2_Template_a_click_10_listener() { i0.ɵɵrestoreView(_r2955); var _r2938 = i0.ɵɵreference(2); var ctx_r2956 = i0.ɵɵnextContext(); return ctx_r2956.confirm(_r2938); });
    i0.ɵɵelementStart(11, "span");
    i0.ɵɵtext(12);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(13, "a", 12);
    i0.ɵɵlistener("click", function NzTableFilterComponent_ng_container_2_Template_a_click_13_listener() { i0.ɵɵrestoreView(_r2955); var _r2938 = i0.ɵɵreference(2); var ctx_r2957 = i0.ɵɵnextContext(); return ctx_r2957.reset(_r2938); });
    i0.ɵɵelementStart(14, "span");
    i0.ɵɵtext(15);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    var _r2939 = i0.ɵɵreference(5);
    var ctx_r2937 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("nzActive", ctx_r2937.isFilterIconActivated)("nzDropdownMenu", _r2939);
    i0.ɵɵadvance(7);
    i0.ɵɵproperty("ngForOf", ctx_r2937.listOfParsedFilter)("ngForTrackBy", ctx_r2937.trackByValue);
    i0.ɵɵadvance(4);
    i0.ɵɵtextInterpolate(ctx_r2937.locale.filterConfirm);
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate(ctx_r2937.locale.filterReset);
} }
var NzTableFilterComponent = /** @class */ (function () {
    function NzTableFilterComponent(cdr, i18n) {
        this.cdr = cdr;
        this.i18n = i18n;
        this.contentTemplate = null;
        this.customFilter = false;
        this.extraTemplate = null;
        this.filterMultiple = true;
        this.listOfFilter = [];
        this.filterChange = new EventEmitter();
        this.destroy$ = new Subject();
        this.locale = {};
        this.isChanged = false;
        this.isFilterIconActivated = false;
        this.listOfParsedFilter = [];
    }
    NzTableFilterComponent.prototype.trackByValue = function (_, item) {
        return item.value;
    };
    NzTableFilterComponent.prototype.check = function (filter) {
        this.isChanged = true;
        if (this.filterMultiple) {
            filter.checked = !filter.checked;
        }
        else {
            this.listOfParsedFilter.forEach(function (item) { return (item.checked = item === filter); });
        }
    };
    NzTableFilterComponent.prototype.confirm = function (filterTrigger) {
        filterTrigger.hide();
        this.onFilterChange();
    };
    NzTableFilterComponent.prototype.reset = function (filterTrigger) {
        this.isChanged = true;
        this.listOfParsedFilter = this.parseListOfFilter(this.listOfFilter, true);
        filterTrigger.hide();
        this.onFilterChange();
    };
    NzTableFilterComponent.prototype.onVisibleChange = function (value) {
        if (!value) {
            this.onFilterChange();
        }
    };
    NzTableFilterComponent.prototype.onFilterChange = function () {
        this.isFilterIconActivated = this.getActivatedStatus(this.listOfParsedFilter);
        if (this.isChanged) {
            var listOfChecked = this.listOfParsedFilter.filter(function (_a) {
                var checked = _a.checked;
                return checked;
            }).map(function (_a) {
                var value = _a.value;
                return value;
            });
            if (this.filterMultiple) {
                this.filterChange.emit(listOfChecked);
            }
            else {
                this.filterChange.emit(listOfChecked[0] || null);
            }
            this.isChanged = false;
        }
    };
    NzTableFilterComponent.prototype.parseListOfFilter = function (listOfFilter, reset) {
        return listOfFilter.map(function (item) {
            var checked = reset ? false : !!item.byDefault;
            return { text: item.text, value: item.value, checked: checked };
        });
    };
    NzTableFilterComponent.prototype.getActivatedStatus = function (listOfParsedFilter) {
        return listOfParsedFilter.some(function (item) { return item.checked; });
    };
    NzTableFilterComponent.prototype.ngOnInit = function () {
        var _this = this;
        this.i18n.localeChange.pipe(takeUntil(this.destroy$)).subscribe(function () {
            _this.locale = _this.i18n.getLocaleData('Table');
            _this.cdr.markForCheck();
        });
    };
    NzTableFilterComponent.prototype.ngOnChanges = function (changes) {
        var listOfFilter = changes.listOfFilter;
        if (listOfFilter && this.listOfFilter && this.listOfFilter.length) {
            this.listOfParsedFilter = this.parseListOfFilter(this.listOfFilter);
            this.isFilterIconActivated = this.getActivatedStatus(this.listOfParsedFilter);
        }
    };
    NzTableFilterComponent.prototype.ngOnDestroy = function () {
        this.destroy$.next();
        this.destroy$.complete();
    };
    /** @nocollapse */ NzTableFilterComponent.ɵfac = function NzTableFilterComponent_Factory(t) { return new (t || NzTableFilterComponent)(i0.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0.ɵɵdirectiveInject(i1.NzI18nService)); };
    /** @nocollapse */ NzTableFilterComponent.ɵcmp = i0.ɵɵdefineComponent({ type: NzTableFilterComponent, selectors: [["nz-table-filter"]], hostVars: 2, hostBindings: function NzTableFilterComponent_HostBindings(rf, ctx) { if (rf & 2) {
            i0.ɵɵclassProp("ant-table-filter-column", true);
        } }, inputs: { contentTemplate: "contentTemplate", customFilter: "customFilter", extraTemplate: "extraTemplate", filterMultiple: "filterMultiple", listOfFilter: "listOfFilter" }, outputs: { filterChange: "filterChange" }, features: [i0.ɵɵNgOnChangesFeature], decls: 3, vars: 3, consts: [[1, "ant-table-filter-column-title"], [3, "ngTemplateOutlet"], [4, "ngIf", "ngIfElse"], [3, "nzActive", "nzDropdownMenu", "nzVisibleChange"], ["filterTrigger", "nzFilterTrigger"], ["nz-icon", "", "nzType", "filter", "nzTheme", "fill"], ["filterMenu", "nzDropdownMenu"], [1, "ant-table-filter-dropdown"], ["nz-menu", ""], ["nz-menu-item", "", 3, "click", 4, "ngFor", "ngForOf", "ngForTrackBy"], [1, "ant-table-filter-dropdown-btns"], [1, "ant-table-filter-dropdown-link", "confirm", 3, "click"], [1, "ant-table-filter-dropdown-link", "clear", 3, "click"], ["nz-menu-item", "", 3, "click"], ["nz-radio", "", 3, "ngModel", "ngModelChange", 4, "ngIf"], ["nz-checkbox", "", 3, "ngModel", "ngModelChange", 4, "ngIf"], ["nz-radio", "", 3, "ngModel", "ngModelChange"], ["nz-checkbox", "", 3, "ngModel", "ngModelChange"]], template: function NzTableFilterComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "span", 0);
            i0.ɵɵtemplate(1, NzTableFilterComponent_ng_template_1_Template, 0, 0, "ng-template", 1);
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(2, NzTableFilterComponent_ng_container_2_Template, 16, 6, "ng-container", 2);
        } if (rf & 2) {
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngTemplateOutlet", ctx.contentTemplate);
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngIf", !ctx.customFilter)("ngIfElse", ctx.extraTemplate);
        } }, directives: [i2.NgTemplateOutlet, i2.NgIf, i3.NzFilterTriggerComponent, i4.NzIconDirective, i5.NzDropdownMenuComponent, i6.NzMenuDirective, i2.NgForOf, i6.NzMenuItemDirective, i7.NzRadioComponent, i8.NgControlStatus, i8.NgModel, i9.NzCheckboxComponent], encapsulation: 2, changeDetection: 0 });
    return NzTableFilterComponent;
}());
export { NzTableFilterComponent };
/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(NzTableFilterComponent, [{
        type: Component,
        args: [{
                selector: 'nz-table-filter',
                preserveWhitespaces: false,
                changeDetection: ChangeDetectionStrategy.OnPush,
                encapsulation: ViewEncapsulation.None,
                template: "\n    <span class=\"ant-table-filter-column-title\">\n      <ng-template [ngTemplateOutlet]=\"contentTemplate\"></ng-template>\n    </span>\n    <ng-container *ngIf=\"!customFilter; else extraTemplate\">\n      <nz-filter-trigger\n        #filterTrigger=\"nzFilterTrigger\"\n        [nzActive]=\"isFilterIconActivated\"\n        [nzDropdownMenu]=\"filterMenu\"\n        (nzVisibleChange)=\"onVisibleChange($event)\"\n      >\n        <i nz-icon nzType=\"filter\" nzTheme=\"fill\"></i>\n      </nz-filter-trigger>\n      <nz-dropdown-menu #filterMenu=\"nzDropdownMenu\">\n        <div class=\"ant-table-filter-dropdown\">\n          <ul nz-menu>\n            <li nz-menu-item *ngFor=\"let f of listOfParsedFilter; trackBy: trackByValue\" (click)=\"check(f)\">\n              <label nz-radio *ngIf=\"!filterMultiple\" [ngModel]=\"f.checked\" (ngModelChange)=\"check(f)\"></label>\n              <label nz-checkbox *ngIf=\"filterMultiple\" [ngModel]=\"f.checked\" (ngModelChange)=\"check(f)\"></label>\n              <span>{{ f.text }}</span>\n            </li>\n          </ul>\n          <div class=\"ant-table-filter-dropdown-btns\">\n            <a class=\"ant-table-filter-dropdown-link confirm\" (click)=\"confirm(filterTrigger)\">\n              <span>{{ locale.filterConfirm }}</span>\n            </a>\n            <a class=\"ant-table-filter-dropdown-link clear\" (click)=\"reset(filterTrigger)\">\n              <span>{{ locale.filterReset }}</span>\n            </a>\n          </div>\n        </div>\n      </nz-dropdown-menu>\n    </ng-container>\n  ",
                host: {
                    '[class.ant-table-filter-column]': 'true'
                }
            }]
    }], function () { return [{ type: i0.ChangeDetectorRef }, { type: i1.NzI18nService }]; }, { contentTemplate: [{
            type: Input
        }], customFilter: [{
            type: Input
        }], extraTemplate: [{
            type: Input
        }], filterMultiple: [{
            type: Input
        }], listOfFilter: [{
            type: Input
        }], filterChange: [{
            type: Output
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 