"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.DateFilter = void 0;
var base_filter_1 = __importDefault(require("../base-filter"));
var aurelia_framework_1 = require("aurelia-framework");
var date_filter_helper_1 = require("./date-filter-helper");
var aurelia_i18n_1 = require("aurelia-i18n");
var DateFilter = (function (_super) {
    __extends(DateFilter, _super);
    function DateFilter() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    DateFilter.prototype.init = function (params) {
        var _this = this;
        this.i18n = aurelia_framework_1.Container.instance.get(aurelia_i18n_1.I18N);
        this.filterHelper = new date_filter_helper_1.DateFilterHelper(function (newVal, oldVal) { return _this._propertyChangedHelper(newVal, oldVal); }, function () { return _this.resetFilterCallBack(); });
        this.filterChangedCallback = params.filterChangedCallback;
        _super.prototype.init.call(this, params);
    };
    DateFilter.prototype._propertyChangedHelper = function (newVal, oldVal) {
        if (!this.firstTime && !this.filterHelper.ignorePropertyChanges) {
            this.DROPDOWN_NAME = this.getModelAsString();
            if (newVal != oldVal) {
                this.setModelInstance();
            }
        }
    };
    DateFilter.prototype.setModelInstance = function () {
        var instance = this.params.api.getFilterInstance(this.params.colDef.field);
        instance.setModel(this.getModelFilter());
    };
    DateFilter.prototype.setModel = function (model) {
        var _this = this;
        if (model == null) {
            this.resetFilter();
        }
        else if (model.filterType == 'date') {
            model.fromDate = model.dateFrom;
            model.toDate = model.dateTo;
            model.selectedDatePreFilter = model.datePreFilter;
            if (this.filterHelper.isAnyDifferent(this.filterHelper, model)) {
                this.filterHelper.ignorePropertyChanges = true;
                this.filterHelper.assignToThis(model);
                this.resetFilterCallBack();
                this.taskQueue.queueMicroTask(function () { return _this.filterHelper.ignorePropertyChanges = false; });
            }
        }
        this.filterChangedCallback();
    };
    DateFilter.prototype.getValue = function () {
        return this.filterHelper.getValue();
    };
    DateFilter.prototype.getModelAsString = function () {
        return this.filterHelper.getModelAsString();
    };
    DateFilter.prototype.getModel = function () {
        return this.filterHelper.getModel('inRange');
    };
    DateFilter.prototype.setupContentGui = function () {
        this.firstTime = false;
        return this.getFilter();
    };
    DateFilter.prototype.setupContentGuiSideFilter = function () {
        return this.getFilter();
    };
    DateFilter.prototype.getFilter = function () {
        return this.filterHelper.getFilter();
    };
    DateFilter.prototype.isFilterActive = function () {
        return this.filterHelper.isFilterActive();
    };
    DateFilter.prototype.resetFilter = function () {
        this.filterHelper.resetFilter();
    };
    DateFilter.prototype.removeFilterValue = function () {
        this.resetFilter();
    };
    DateFilter.prototype.resetFilterCallBack = function () {
        this.DROPDOWN_NAME = this.getModelAsString();
        this.setModelInstance();
    };
    DateFilter.prototype.getModelFilter = function () {
        var modelFilter = this.filterHelper.getModelFilter();
        return modelFilter;
    };
    return DateFilter;
}(base_filter_1.default));
exports.DateFilter = DateFilter;

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