"use strict";
var angular = require("angular");
exports.moduleName = 'rl.ui.components.cardContainer.cardSearch';
exports.componentName = 'rlCardSearch';
exports.controllerName = 'CardSearchController';
exports.defaultSearchPlaceholder = 'Search';
exports.defaultSearchDelay = 1000;
var CardSearchController = (function () {
    function CardSearchController($timeout) {
        this.$timeout = $timeout;
        this.searchLengthError = false;
        this.hasSearchFilter = true;
    }
    Object.defineProperty(CardSearchController.prototype, "searchText", {
        get: function () {
            return this.searchFilter
                ? this.searchFilter.searchText
                : null;
        },
        set: function (search) {
            this.searchFilter.searchText = search;
            this.minSearchLength = this.searchFilter.minSearchLength;
            this.validateSearchLength(search, this.minSearchLength);
            if (this.timer != null) {
                this.$timeout.cancel(this.timer);
            }
            if (!this.searchLengthError) {
                this.timer = this.$timeout(this.cardContainer.dataSource.refresh.bind(this.cardContainer.dataSource), this.delay);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CardSearchController.prototype, "focusOn", {
        get: function () {
            return this.cardContainer.focusSearchOn;
        },
        enumerable: true,
        configurable: true
    });
    CardSearchController.prototype.$onInit = function () {
        var _this = this;
        if (this.cardContainer == null) {
            return;
        }
        this.minSearchError = 'You must enter at least {{cardSearch.minSearchLength}} characters to perform a search';
        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 != null
                ? this.delay
                : exports.defaultSearchDelay;
            this.searchFilter.subscribe(function () {
                _this.searchText = _this.searchFilter.searchText;
            });
        }
    };
    Object.defineProperty(CardSearchController.prototype, "searchPlaceholder", {
        get: function () {
            if (this.hasSearchFilter) {
                return this.cardContainer.searchPlaceholder || exports.defaultSearchPlaceholder;
            }
        },
        enumerable: true,
        configurable: true
    });
    CardSearchController.prototype.validateSearchLength = function (search, minLength) {
        // show error if search string exists but is below minimum size
        this.searchLengthError = search != null
            && search.length > 0
            && search.length < minLength;
    };
    return CardSearchController;
}());
CardSearchController.$inject = ['$timeout'];
exports.CardSearchController = CardSearchController;
var cardSearch = {
    require: { cardContainer: '?^^rlCardContainer' },
    template: require('./cardSearch.ng1.html'),
    controller: exports.controllerName,
    controllerAs: 'cardSearch',
    bindings: {
        delay: '<?searchDelay',
        searchFilter: '<?',
    },
};
angular.module(exports.moduleName, [])
    .component(exports.componentName, cardSearch)
    .controller(exports.controllerName, CardSearchController);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FyZFNlYXJjaC5uZzEuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJjYXJkU2VhcmNoLm5nMS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsaUNBQW1DO0FBT3hCLFFBQUEsVUFBVSxHQUFXLDJDQUEyQyxDQUFDO0FBQ2pFLFFBQUEsYUFBYSxHQUFXLGNBQWMsQ0FBQztBQUN2QyxRQUFBLGNBQWMsR0FBVyxzQkFBc0IsQ0FBQztBQUVoRCxRQUFBLHdCQUF3QixHQUFXLFFBQVEsQ0FBQztBQUM1QyxRQUFBLGtCQUFrQixHQUFXLElBQUksQ0FBQztBQU03QztJQW1DQyw4QkFBb0IsUUFBaUM7UUFBakMsYUFBUSxHQUFSLFFBQVEsQ0FBeUI7UUEvQnJELHNCQUFpQixHQUFZLEtBQUssQ0FBQztRQUVuQyxvQkFBZSxHQUFZLElBQUksQ0FBQztJQTZCd0IsQ0FBQztJQXRCekQsc0JBQUksNENBQVU7YUFBZDtZQUNDLE1BQU0sQ0FBQyxJQUFJLENBQUMsWUFBWTtrQkFDckIsSUFBSSxDQUFDLFlBQVksQ0FBQyxVQUFVO2tCQUM1QixJQUFJLENBQUM7UUFDVCxDQUFDO2FBRUQsVUFBZSxNQUFjO1lBQzVCLElBQUksQ0FBQyxZQUFZLENBQUMsVUFBVSxHQUFHLE1BQU0sQ0FBQztZQUN0QyxJQUFJLENBQUMsZUFBZSxHQUFHLElBQU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