"use strict";
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 core_1 = require("@angular/core");
var moment = require("moment");
var typescript_angular_utilities_1 = require("typescript-angular-utilities");
var __date = typescript_angular_utilities_1.services.date;
var dateFilter_service_1 = require("./dateFilter.service");
var type = 'days';
var DateFilterComponent = (function () {
    function DateFilterComponent(dateUtility) {
        this.count = 0;
        this.dateUtility = dateUtility;
    }
    DateFilterComponent.prototype.setDate = function (date) {
        this.filter.setDateFrom(date);
    };
    DateFilterComponent.prototype.setCount = function (count) {
        var _this = this;
        this.count = count || 0;
        if (this.count > 0) {
            this.filter.dateFrom$.take(1).subscribe(function (dateFrom) {
                _this.filter.setDateTo(moment(dateFrom).subtract((_this.count), type));
            });
        }
        else if (this.count == 0) {
            this.filter.setDateTo(null);
        }
    };
    DateFilterComponent.prototype.clear = function () {
        this.setDate(null);
        this.setCount(0);
    };
    DateFilterComponent.prototype.ngOnInit = function () {
        this.filter.useTime = this.useTime;
        this.showClear = this.showClear != null ? this.showClear : true;
    };
    return DateFilterComponent;
}());
__decorate([
    core_1.Input(),
    __metadata("design:type", dateFilter_service_1.DateFilter)
], DateFilterComponent.prototype, "filter", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", String)
], DateFilterComponent.prototype, "label", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", Boolean)
], DateFilterComponent.prototype, "showClear", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", Boolean)
], DateFilterComponent.prototype, "useDateRange", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", Boolean)
], DateFilterComponent.prototype, "useTime", void 0);
DateFilterComponent = __decorate([
    core_1.Component({
        selector: 'rlDateFilter',
        template: require('./dateFilter.html'),
        changeDetection: core_1.ChangeDetectionStrategy.OnPush,
    }),
    __metadata("design:paramtypes", [__date.DateUtility])
], DateFilterComponent);
exports.DateFilterComponent = DateFilterComponent;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0ZUZpbHRlci5jb21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJkYXRlRmlsdGVyLmNvbXBvbmVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsc0NBQWtGO0FBQ2xGLCtCQUFpQztBQUVqQyw2RUFBd0Q7QUFDeEQsSUFBTyxNQUFNLEdBQUcsdUNBQVEsQ0FBQyxJQUFJLENBQUM7QUFFOUIsMkRBQWtEO0FBR2xELElBQU0sSUFBSSxHQUFzQixNQUFNLENBQUM7QUFPdkMsSUFBYSxtQkFBbUI7SUFXL0IsNkJBQVksV0FBK0I7UUFKM0MsVUFBSyxHQUFXLENBQUMsQ0FBQztRQUtqQixJQUFJLENBQUMsV0FBVyxHQUFHLFdBQVcsQ0FBQztJQUNoQyxDQUFDO0lBRUQscUNBQU8sR0FBUCxVQUFRLElBQW1CO1FBQzFCLElBQUksQ0FBQyxNQUFNLENBQUMsV0FBVyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBQy9CLENBQUM7SUFFRCxzQ0FBUSxHQUFSLFVBQVMsS0FBYTtRQUF0QixpQkFVQztRQVRBLElBQUksQ0FBQyxLQUFLLEdBQUcsS0FBSyxJQUFJLENBQUMsQ0FBQztRQUV4QixFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsS0FBSyxHQUFHLENBQUMsQ0FBQyxD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