"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var lodash_1 = require("lodash");
var moment = require("moment");
var filter_1 = require("../filter");
var DateFilter = (function (_super) {
    __extends(DateFilter, _super);
    function DateFilter(settings, dateUtility, transformService) {
        var _this = _super.call(this) || this;
        _this.predicate = function (item, filterValue) {
            if (!filterValue || !_this.date.isDate(filterValue.dateFrom)) {
                return true;
            }
            if (filterValue.dateTo) {
                var itemDate = _this.getValue(item);
                var dateFrom = void 0;
                //have to set the dateFrom to a valid Date object for comparisons.
                if (_this.useTime) {
                    dateFrom = moment(filterValue.dateFrom);
                }
                else {
                    //increase it by 1 days. to inlcude the selected date in the range.
                    dateFrom = moment(filterValue.dateFrom).add(1, 'days');
                }
                return _this.date.dateInRange(itemDate, filterValue.dateTo, filterValue.dateFrom);
            }
            else {
                if (_this.useTime) {
                    return _this.date.sameDateTime(_this.getValue(item), filterValue.dateFrom);
                }
                else {
                    return _this.date.sameDate(_this.getValue(item), filterValue.dateFrom);
                }
            }
        };
        _this.date = dateUtility;
        _this.transformService = transformService;
        _this.valueSelector = settings.valueSelector;
        _this.type = settings.type;
        return _this;
        // this.showClear = settings.showClear;
        // this.useDateRange = settings.useDateRange;
        // this.useTime = settings.useTime != null ? settings.useTime : false;
        // this.label = settings.label;
        // this.template = `<rl-date-filter filter="filter" source="dataSource" label="{{filter.label}}" include-time="filter.useTime"
        // 							     include-date-range="filter.useDateRange" clear-button="filter.showClear"></rl-date-filter>`;
    }
    Object.defineProperty(DateFilter.prototype, "dateFrom$", {
        get: function () {
            return this.value$.asObservable().map(function (value) { return value ? value.dateFrom : null; });
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(DateFilter.prototype, "dateTo$", {
        get: function () {
            return this.value$.asObservable().map(function (value) { return value ? value.dateTo : null; });
        },
        enumerable: true,
        configurable: true
    });
    DateFilter.prototype.setDateFrom = function (value) {
        var updatedValue = lodash_1.clone(this.value$.getValue()) || {};
        updatedValue.dateFrom = value;
        this.value$.next(updatedValue);
    };
    DateFilter.prototype.setDateTo = function (value) {
        var updatedValue = lodash_1.clone(this.value$.getValue()) || {};
        updatedValue.dateTo = value;
        this.value$.next(updatedValue);
    };
    DateFilter.prototype.serialize = function () {
        return this.value$.asObservable().map(function (value) {
            if (!value || !(value.dateFrom || value.dateTo)) {
                return null;
            }
            return value;
        });
    };
    DateFilter.prototype.getValue = function (item) {
        return this.transformService.getValue(item, this.valueSelector);
    };
    return DateFilter;
}(filter_1.Filter));
exports.DateFilter = DateFilter;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0ZUZpbHRlci5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiZGF0ZUZpbHRlci5zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUNBLGlDQUErQjtBQUMvQiwrQkFBaUM7QUFNakMsb0NBQTRDO0FBeUI1QztJQUEyQyw4QkFBbUM7SUF5QjdFLG9CQUFZLFFBQXdDLEVBQ2hELFdBQWdDLEVBQ2hDLGdCQUErQztRQUZuRCxZQUdDLGlCQUFPLFNBYVA7UUFjRCxlQUFTLEdBQUcsVUFBQyxJQUFlLEVBQUUsV0FBNkI7WUFDMUQsRUFBRSxDQUFDLENBQUMsQ0FBQyxXQUFXLElBQUksQ0FBQyxLQUFJLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxXQUFXLENBQUMsUUFBUSxDQUFDLENBQUMsQ0FBQyxDQUFDO2dCQUM3RCxNQUFNLENBQUMsSUFBSSxDQUFDO1lBQ2IsQ0FBQztZQUVELEVBQUUsQ0FBQyxDQUFDLFdBQVcsQ0FBQyxNQUFNLENBQUMsQ0FBQyxDQUFDO2dCQUN4QixJQUFJLFFBQVEsR0FBa0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