"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 __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NumberFilter = void 0;
var aurelia_framework_1 = require("aurelia-framework");
var aurelia_i18n_1 = require("aurelia-i18n");
var base_filter_1 = __importDefault(require("../base-filter"));
var number_filter_helper_1 = require("./number-filter-helper");
var NumberFilter = (function (_super) {
    __extends(NumberFilter, _super);
    function NumberFilter() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.DROPDOWN_NAME = null;
        return _this;
    }
    NumberFilter.prototype.init = function (params) {
        var _this = this;
        this.filterChangedCallback = params.filterChangedCallback;
        this.filterHelper = new number_filter_helper_1.NumberFilterHelper(function (model) {
            if (_this.isDestroyed()) {
                return;
            }
            var instance = _this.params.api.getFilterInstance(_this.params.colDef.field);
            instance.setModel(model);
        });
        _super.prototype.init.call(this, params);
        this.i18n = aurelia_framework_1.Container.instance.get(aurelia_i18n_1.I18N);
        this.params = params;
    };
    NumberFilter.prototype.isFilterActive = function () {
        return this.filterHelper.isFilterActive();
    };
    NumberFilter.prototype.onParentModelChanged = function (parentModel) {
        var _a;
        this.filterHelper.type = ((parentModel === null || parentModel === void 0 ? void 0 : parentModel.type) ? parentModel.type : ((_a = this.filterHelper.type) !== null && _a !== void 0 ? _a : 'equals'));
        this.filterHelper.fromNumber = ((parentModel === null || parentModel === void 0 ? void 0 : parentModel.filter) ? parentModel.filter : null);
        this.filterHelper.toNumber = ((parentModel === null || parentModel === void 0 ? void 0 : parentModel.filterTo) ? parentModel.filterTo : null);
    };
    NumberFilter.prototype.setModel = function (model) {
        var _a;
        var _b;
        if (model == null) {
            (_a = (_b = this.filterHelper).type) !== null && _a !== void 0 ? _a : (_b.type = 'equals');
            this.filterHelper.fromNumber = null;
            this.filterHelper.toNumber = null;
        }
        else if ((model === null || model === void 0 ? void 0 : model.filterType) == 'number') {
            this.filterHelper.type = model.type;
            this.filterHelper.fromNumber = model.filter;
            this.filterHelper.toNumber = model.filterTo;
        }
        this.filterChangedCallback();
    };
    NumberFilter.prototype.getGui = function () {
        return _super.prototype.getGui.call(this);
    };
    NumberFilter.prototype.getModel = function () {
        var model = { filterType: 'number', displayEmptyFields: this.filterHelper.displayEmptyFields };
        if (this.isFilterActive()) {
            if (this.filterHelper.type == 'equals') {
                if (!this.filterHelper.fromNumberIsEmpty()) {
                    return Object.assign(model, { type: 'equals', filter: this.filterHelper.fromNumber, filterTo: null });
                }
            }
            else {
                if (!this.filterHelper.fromNumberIsEmpty() && !this.filterHelper.toNumberIsEmpty()) {
                    return Object.assign(model, { type: 'inRange', filter: this.filterHelper.fromNumber, filterTo: this.filterHelper.toNumber });
                }
                else if (!this.filterHelper.toNumberIsEmpty()) {
                    return Object.assign(model, { type: 'lessThan', filter: null, filterTo: this.filterHelper.toNumber });
                }
                else if (!this.filterHelper.fromNumberIsEmpty()) {
                    return Object.assign(model, { type: 'greaterThan', filter: this.filterHelper.fromNumber, filterTo: null });
                }
            }
            return model;
        }
        return Object.assign(model, { type: this.filterHelper.type });
    };
    NumberFilter.prototype.setupContentGui = function () {
        return this.filterHelper.setupContentGui();
    };
    NumberFilter.prototype.resetFilter = function () {
        this.filterHelper.resetFilter();
    };
    NumberFilter.prototype.removeFilterValue = function () {
        this.resetFilter();
    };
    NumberFilter.prototype.getValue = function () {
        return this.filterHelper.getValue();
    };
    NumberFilter.prototype.getModelAsString = function () {
        return this.filterHelper.getModelAsString();
    };
    NumberFilter.prototype.setupContentGuiSideFilter = function () {
        return this.filterHelper.setupContentGuiSideFilter();
    };
    NumberFilter.prototype.applyObservers = function () {
        var _this = this;
        this.dispose();
        this.disposables.push(this.bindingEngine.propertyObserver(this.filterHelper, 'displayEmptyFields').subscribe(function () { return _this.filterHelper.displayEmptyFieldsChanged(); }));
    };
    return NumberFilter;
}(base_filter_1.default));
exports.NumberFilter = NumberFilter;

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