"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BooleanFilter = void 0;
var aurelia_binding_1 = require("aurelia-binding");
var base_filter_1 = __importDefault(require("../base-filter"));
var boolean_filter_helper_1 = require("./boolean-filter-helper");
var BooleanFilter = exports.BooleanFilter = (function (_super) {
    __extends(BooleanFilter, _super);
    function BooleanFilter() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    BooleanFilter.prototype.init = function (params) {
        this.groupName = Math.random().toString();
        this.filterHelper = new boolean_filter_helper_1.BooleanFilterHelper();
        this.filterChangedCallback = params.filterChangedCallback;
        if (this.i18n != null) {
            this.filterHelper.setFilterNames([this.i18n.tr('grid.noFilter', { ns: "common" }), this.i18n.tr('grid.yes', { ns: "common" }), this.i18n.tr('grid.no', { ns: "common" })]);
        }
        this.selected = this.filterHelper.getFilterNone();
        this.selectedIndex = 0;
        _super.prototype.init.call(this, params);
    };
    BooleanFilter.prototype.resetFilter = function () {
        this.selectedIndex = this.filterHelper.getFilterValueIndex(this.filterHelper.getFilterNone());
    };
    BooleanFilter.prototype.removeFilterValue = function () {
        var _this = this;
        this.selectedIndex = this.filterHelper.FILTER_VALUES.findIndex(function (x) { return x == _this.filterHelper.FILTER_NONE; });
    };
    BooleanFilter.prototype.setupContentGui = function () {
        this.firstTime = false;
        return this.filterHelper.setupContentGui(this.groupName);
    };
    BooleanFilter.prototype.setupContentGuiSideFilter = function () {
        return this.filterHelper.setupContentGuiSideFilter();
    };
    BooleanFilter.prototype.getValue = function () {
        return this.filterHelper.getValue(this.selectedIndex);
    };
    BooleanFilter.prototype.getModelAsString = function () {
        return this.filterHelper.getModelAsString(this.selectedIndex);
    };
    BooleanFilter.prototype.selectedIndexChanged = function (newVal, oldVal) {
        if (newVal != oldVal && !this.firstTime) {
            this.DROPDOWN_NAME = this.getModelAsString();
            var instance = this.params.api.getFilterInstance(this.params.colDef.field);
            instance.setModel({ "filterType": "boolean", "filter": this.filterHelper.getFilterValue(this.selectedIndex) });
        }
    };
    BooleanFilter.prototype.isFilterActive = function () {
        return this.selected !== this.filterHelper.getFilterNone();
    };
    BooleanFilter.prototype.getModel = function () {
        if (this.selected === this.filterHelper.getFilterNone())
            return null;
        return { "filterType": "boolean", "filter": this.selected };
    };
    BooleanFilter.prototype.setModel = function (model) {
        if (model == null) {
            this.selected = this.filterHelper.getFilterNone();
        }
        else if (model.filterType == 'boolean') {
            this.selected = model.filter;
        }
        this.selectedIndex = this.filterHelper.getFilterValueIndex(this.selected);
        this.filterChangedCallback();
    };
    __decorate([
        aurelia_binding_1.observable,
        __metadata("design:type", Number)
    ], BooleanFilter.prototype, "selectedIndex", void 0);
    return BooleanFilter;
}(base_filter_1.default));

//# sourceMappingURL=boolean-filter.js.map
