"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 __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var core_1 = require("@angular/core");
var rxjs_1 = require("rxjs");
var cardContainer_1 = require("../../cardContainer");
var index_1 = require("../../filters/index");
exports.defaultSearchPlaceholder = 'Search';
exports.defaultSearchDelay = 1000;
var CardSearchComponent = (function () {
    function CardSearchComponent(cardContainer) {
        this.hasSearchFilter = true;
        this.searchChanges$ = new rxjs_1.Subject();
        this.cardContainer = cardContainer;
        this.searchPlaceholder = exports.defaultSearchPlaceholder;
    }
    Object.defineProperty(CardSearchComponent.prototype, "searchLengthError$", {
        get: function () {
            var _this = this;
            return this.searchFilter.searchText$.map(function (search) {
                // show error if search string exists but is below minimum size
                return search != null
                    && search.length > 0
                    && search.length < _this.searchFilter.minSearchLength;
            });
        },
        enumerable: true,
        configurable: true
    });
    CardSearchComponent.prototype.ngOnInit = function () {
        var _this = this;
        if (this.searchFilter == null) {
            var filter = this.cardContainer.searchFilter;
            this.searchFilter = filter;
            if (filter == null) {
                this.hasSearchFilter = false;
            }
        }
        if (this.hasSearchFilter) {
            this.delay = this.delay || exports.defaultSearchDelay;
            this.searchChanges$.debounceTime(this.delay)
                .distinctUntilChanged()
                .subscribe(function (search) { return _this.searchFilter.setSearch(search); });
        }
    };
    Object.defineProperty(CardSearchComponent.prototype, "minSearchError", {
        get: function () {
            return "You must enter at least " + this.searchFilter.minSearchLength + " characters to perform a search";
        },
        enumerable: true,
        configurable: true
    });
    return CardSearchComponent;
}());
__decorate([
    core_1.Input(),
    __metadata("design:type", Number)
], CardSearchComponent.prototype, "delay", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", index_1.SearchFilter)
], CardSearchComponent.prototype, "searchFilter", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", String)
], CardSearchComponent.prototype, "searchPlaceholder", void 0);
CardSearchComponent = __decorate([
    core_1.Component({
        selector: 'rlCardSearch',
        template: require('./cardSearch.html'),
        changeDetection: core_1.ChangeDetectionStrategy.OnPush,
    }),
    __param(0, core_1.Inject(core_1.forwardRef(function () { return cardContainer_1.CardContainerComponent; }))),
    __metadata("design:paramtypes", [cardContainer_1.CardContainerComponent])
], CardSearchComponent);
exports.CardSearchComponent = CardSearchComponent;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FyZFNlYXJjaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbImNhcmRTZWFyY2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7OztBQUFBLHNDQUFzRztBQUN0Ryw2QkFBMkM7QUFFM0MscURBQTZEO0FBQzdELDZDQUFtRDtBQUV0QyxRQUFBLHdCQUF3QixHQUFXLFFBQVEsQ0FBQztBQUM1QyxRQUFBLGtCQUFrQixHQUFXLElBQUksQ0FBQztBQU8vQyxJQUFhLG1CQUFtQjtJQVUvQiw2QkFBOEQsYUFBd0M7UUFMdEcsb0JBQWUsR0FBWSxJQUFJLENBQUM7UUFDaEMsbUJBQWMsR0FBb0IsSUFBSSxjQUFPLEVBQVUsQ0FBQztRQUt2RCxJQUFJLENBQUMsYUFBYSxHQUFHLGFBQWEsQ0FBQztRQUNuQyxJQUFJLENBQUMsaUJBQWlCLEdBQUcsZ0NBQXdCLENBQUM7SUFDbkQs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