"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 lodash_1 = require("lodash");
var dataPager_service_1 = require("./paging/dataPager/dataPager.service");
var index_1 = require("./sorts/index");
var index_2 = require("./filters/index");
var card_1 = require("./card/card");
var index_3 = require("../cards/index");
var index_4 = require("./templates/index");
var columnHeader_template_1 = require("./templates/columnHeader.template");
var cardContainerBuilder_service_1 = require("./builder/cardContainerBuilder.service");
exports.cardContainerInputs = {
    builder: 'builder',
    save: 'save',
};
exports.defaultMaxColumnSorts = 2;
var CardContainerComponent = (function () {
    function CardContainerComponent(pager, searchFilter, sortManager) {
        this.type = cardContainerBuilder_service_1.CardContainerType.standard;
        this.injectedPager = pager;
        this.injectedSearchFilter = searchFilter;
        this.sortManager = sortManager;
        this.save = function () { return null; };
    }
    Object.defineProperty(CardContainerComponent.prototype, "cards", {
        get: function () {
            return this.cardChildren.toArray();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CardContainerComponent.prototype, "hasItems$", {
        get: function () {
            return this.dataSource.dataSet$.map(function (dataSet) { return dataSet && !!dataSet.length; });
        },
        enumerable: true,
        configurable: true
    });
    CardContainerComponent.prototype.ngOnInit = function () {
        var _this = this;
        if (this.builder != null) {
            this.paging = this.builder.paging;
            this.maxColumnSorts = this.builder.maxColumnSorts;
            this.permanentFooters = this.builder.permanentFooters;
            this.columns = this.builder.columns;
            this.dataSource = this.builder.dataSource;
            this.filters = this.builder.filters;
            if (this.builder.search) {
                this.searchFilter = this.injectedSearchFilter;
                this.filters.push(this.searchFilter);
            }
        }
        this.permanentFooters = lodash_1.isUndefined(this.permanentFooters) ? false : this.permanentFooters;
        this.maxColumnSorts = this.maxColumnSorts || exports.defaultMaxColumnSorts;
        this.sortDirection = index_1.SortDirection;
        if (this.filters) {
            this.dataSource.filters = this.filters;
        }
        if (this.paging) {
            this.dataSource.pager = this.injectedPager;
        }
        // need a way to customize the sorts?
        this.sortManager.setup([], function (name) { return _this.lookupColumn(name); }, this.maxColumnSorts);
        this.dataSource.sorter = this.sortManager;
        this.dataSource.init();
    };
    CardContainerComponent.prototype.ngAfterContentInit = function () {
        this.containerHeader = this.containerHeader || this.externalContainerHeader;
        this.containerFooter = this.containerFooter || this.externalContainerFooter;
        this.cardContent = this.cardContent || this.externalCardContent;
        this.cardFooter = this.cardFooter || this.externalCardFooter;
        if (!this.columnHeaders.length && this.externalColumnHeaders) {
            this.columnHeaders = this.externalColumnHeaders;
        }
        if (!this.columnTemplates.length && this.externalColumnTemplates) {
            this.columnTemplates = this.externalColumnTemplates;
        }
    };
    CardContainerComponent.prototype.openCard = function () {
        return lodash_1.every(lodash_1.map(this.cards, function (card) { return card.close(); }));
    };
    CardContainerComponent.prototype.sort = function (column) {
        this.sortManager.updateSorts(column);
    };
    CardContainerComponent.prototype.getColumnTemplate = function (columnName) {
        return this.columnHeaders.filter(function (column) { return column.name === columnName; })[0];
    };
    CardContainerComponent.prototype.lookupColumn = function (label) {
        return lodash_1.find(this.columns, function (column) {
            return column.label === label;
        });
    };
    return CardContainerComponent;
}());
__decorate([
    core_1.ContentChild(index_4.ContainerHeaderTemplate),
    __metadata("design:type", index_4.ContainerHeaderTemplate)
], CardContainerComponent.prototype, "containerHeader", void 0);
__decorate([
    core_1.ContentChild(index_4.ContainerFooterTemplate),
    __metadata("design:type", index_4.ContainerFooterTemplate)
], CardContainerComponent.prototype, "containerFooter", void 0);
__decorate([
    core_1.ContentChild(index_3.CardContentTemplate),
    __metadata("design:type", index_3.CardContentTemplate)
], CardContainerComponent.prototype, "cardContent", void 0);
__decorate([
    core_1.ContentChild(index_3.CardFooterTemplate),
    __metadata("design:type", index_3.CardFooterTemplate)
], CardContainerComponent.prototype, "cardFooter", void 0);
__decorate([
    core_1.ContentChildren(index_4.ColumnContentTemplate),
    __metadata("design:type", core_1.QueryList)
], CardContainerComponent.prototype, "columnTemplates", void 0);
__decorate([
    core_1.ContentChildren(columnHeader_template_1.ColumnHeaderTemplate),
    __metadata("design:type", core_1.QueryList)
], CardContainerComponent.prototype, "columnHeaders", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", index_4.ContainerHeaderTemplate)
], CardContainerComponent.prototype, "externalContainerHeader", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", index_4.ContainerFooterTemplate)
], CardContainerComponent.prototype, "externalContainerFooter", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", index_3.CardContentTemplate)
], CardContainerComponent.prototype, "externalCardContent", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", index_3.CardFooterTemplate)
], CardContainerComponent.prototype, "externalCardFooter", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", core_1.QueryList)
], CardContainerComponent.prototype, "externalColumnTemplates", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", core_1.QueryList)
], CardContainerComponent.prototype, "externalColumnHeaders", void 0);
__decorate([
    core_1.ViewChildren(card_1.CardComponent),
    __metadata("design:type", core_1.QueryList)
], CardContainerComponent.prototype, "cardChildren", void 0);
CardContainerComponent = __decorate([
    core_1.Component({
        selector: 'rlCardContainer',
        template: require('./cardContainer.html'),
        inputs: [
            exports.cardContainerInputs.builder,
            exports.cardContainerInputs.save,
        ],
        providers: [dataPager_service_1.DataPager, index_2.SearchFilter, index_1.SortManagerService],
        changeDetection: core_1.ChangeDetectionStrategy.OnPush,
    }),
    __metadata("design:paramtypes", [dataPager_service_1.DataPager,
        index_2.SearchFilter,
        index_1.SortManagerService])
], CardContainerComponent);
exports.CardContainerComponent = CardContainerComponent;
//# sourceMappingURL=data:application/json;base64, 