"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 rxjs_1 = require("rxjs");
var moment = require("moment");
var typescript_angular_utilities_1 = require("typescript-angular-utilities");
var __date = typescript_angular_utilities_1.services.date;
var __timezone = typescript_angular_utilities_1.services.timezone;
var index_1 = require("../../source/components/cardContainer/builder/index");
var rangeLow = 1;
var rangeHigh = 101;
var items = lodash_1.map(lodash_1.range(rangeLow, rangeHigh), function (num) {
    return {
        id: num,
        name: 'Item' + num,
        value: num,
    };
});
var CardsBootstrapper = (function () {
    function CardsBootstrapper(timezone, cardContainerBuilder) {
        this.alwaysOpen = false;
        this.data = items;
        this.submitAsync = function (data) {
            return new Promise(function (resolve, reject) {
                setTimeout(function () {
                    console.log(data);
                    resolve();
                }, 1000);
            });
        };
        timezone.setCurrentTimezone('-05:00');
        this.options = [1, 2, 3, 4, 5];
        this.columns = [
            {
                name: 'name',
                label: 'Name',
                size: 6,
                getValue: 'name',
            },
            {
                name: 'value',
                label: 'Value',
                size: 6,
                getValue: 'value',
            },
        ];
        this.builder = this.setupCardContainer(cardContainerBuilder);
        this.selectBuilder = this.setupCardContainer(cardContainerBuilder);
        this.searchBuilder = this.setupCardContainer(cardContainerBuilder);
        this.builderWithFilterGroups = this.setupCardContainerWithFilterGroups(cardContainerBuilder);
        this.builderWithSelectFilter = this.setupCardContainerWithSelectFilter(cardContainerBuilder);
        this.builderWithDateFilter = this.setupCardContainerWithDateFilter(cardContainerBuilder);
        // const searchFilter = this.builder.useSearch();
        // searchFilter.minSearchLength = 5;
    }
    CardsBootstrapper.prototype.setupCardContainer = function (cardContainerBuilder) {
        var builder = cardContainerBuilder.getInstance({
            paging: true,
            search: true,
        });
        cardContainerBuilder.buildObservableDataSource(builder, rxjs_1.Observable.of(items).delay(1000));
        cardContainerBuilder.addColumn(builder, {
            name: 'name',
            label: 'Name',
            size: 6,
            getValue: 'name',
        });
        cardContainerBuilder.addColumn(builder, {
            name: 'value',
            label: 'Value',
            size: 6,
            getValue: 'value',
        });
        return builder;
    };
    CardsBootstrapper.prototype.setupCardContainerWithFilterGroups = function (cardContainerBuilder) {
        var builder = cardContainerBuilder.getInstance({
            paging: true,
            search: true,
        });
        cardContainerBuilder.buildObservableDataSource(builder, rxjs_1.Observable.of(items).delay(1000));
        cardContainerBuilder.addColumn(builder, {
            name: 'name',
            label: 'Name',
            size: 6,
            getValue: 'name',
        });
        cardContainerBuilder.addColumn(builder, {
            name: 'value',
            label: 'Value',
            size: 6,
            getValue: 'value',
            template: '<b>{{myItem.value}}</b>',
        });
        this.rangeFilterGroup = cardContainerBuilder.buildRangeFilterGroup(builder, {
            type: 'testRangeGroup',
            label: 'Range Filter Group',
            getValue: 'value',
            options: [
                {
                    label: 'All',
                },
                {
                    label: '5 - 10',
                    highInclusive: 10,
                    lowInclusive: 5,
                },
                {
                    label: '< 5',
                    highExclusive: 5,
                },
            ],
        });
        this.modeFilterGroup = cardContainerBuilder.buildModeFilterGroup(builder, {
            type: 'testModeGroup',
            label: 'Mode Filter Group',
            getValue: 'value',
            options: [
                {
                    label: 'All',
                    displayAll: true,
                },
                {
                    label: 'Value Equals 3',
                    value: 3,
                },
                {
                    label: 'Value Equals 10',
                    value: 10,
                },
            ],
        });
        this.disabledFilterGroup = cardContainerBuilder.buildFilterGroup(builder, {
            type: 'testGroup',
            label: 'Disabled Filter Group',
            options: [
                {
                    label: 'Show',
                    predicate: function (item) { return true; },
                    serialize: function () { return 'show'; },
                },
                {
                    label: 'Hide',
                    predicate: function (item) { return false; },
                    serialize: function () { return 'hide'; },
                },
            ],
        });
        this.modeFilterGroup.serialize().skip(1).subscribe(function (value) { return console.log('mode filter change', value); });
        this.rangeFilterGroup.serialize().skip(1).subscribe(function (value) { return console.log('range filter change', value); });
        this.disabledFilterGroup.serialize().skip(1).subscribe(function (value) { return console.log('disabled filter change', value); });
        return builder;
    };
    CardsBootstrapper.prototype.setupCardContainerWithSelectFilter = function (cardContainerBuilder) {
        var builder = cardContainerBuilder.getInstance({
            paging: true,
            search: true,
        });
        cardContainerBuilder.buildObservableDataSource(builder, rxjs_1.Observable.of(items).delay(1000));
        cardContainerBuilder.addColumn(builder, {
            name: 'name',
            label: 'Name',
            size: 6,
            getValue: 'name',
        });
        cardContainerBuilder.addColumn(builder, {
            name: 'value',
            label: 'Value',
            size: 6,
            getValue: 'value',
            template: '<b>{{myItem.value}}</b>',
        });
        this.selectFilter = cardContainerBuilder.buildSelectFilter(builder, {
            valueSelector: 'value',
        });
        this.selectFilter.serialize().skip(1).subscribe(function (value) { return console.log('select filter change', value); });
        return builder;
    };
    CardsBootstrapper.prototype.setupCardContainerWithDateFilter = function (cardContainerBuilder) {
        var builder = cardContainerBuilder.getInstance({
            paging: true,
            search: true,
        });
        var itemsWithDates = lodash_1.map(items, function (item) {
            item.date = moment().subtract(item.value, 'days');
            return item;
        });
        cardContainerBuilder.buildObservableDataSource(builder, rxjs_1.Observable.of(itemsWithDates).delay(1000));
        cardContainerBuilder.addColumn(builder, {
            name: 'name',
            label: 'Name',
            size: 6,
            getValue: 'name',
        });
        cardContainerBuilder.addColumn(builder, {
            name: 'date',
            label: 'Date',
            size: 6,
            getValue: 'date',
            template: '<b>{{myItem.date}}</b>',
        });
        this.dateFilter = cardContainerBuilder.buildDateFilter(builder, {
            type: 'dateFilter',
            valueSelector: 'date',
        });
        this.dateFilter.serialize().skip(1).subscribe(function (value) { return console.log('date filter change', lodash_1.mapValues(value, function (date) { return date != null ? date.format(__date.defaultFormats.dateTimeFormat) : null; })); });
        return builder;
    };
    return CardsBootstrapper;
}());
CardsBootstrapper = __decorate([
    core_1.Component({
        selector: 'tsCardsBootstrapper',
        template: require('./cardsNg2.html'),
    }),
    __metadata("design:paramtypes", [__timezone.TimezoneService, index_1.CardContainerBuilderService])
], CardsBootstrapper);
exports.CardsBootstrapper = CardsBootstrapper;
//# sourceMappingURL=data:application/json;base64, 