"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
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 lodash_1 = require("lodash");
var typescript_angular_utilities_1 = require("typescript-angular-utilities");
var __notification = typescript_angular_utilities_1.services.notification;
var cardContainer_1 = require("../cardContainer");
var form_1 = require("../../form/form");
var async_service_1 = require("../../../services/async/async.service");
var form_service_1 = require("../../../services/form/form.service");
exports.cardInputs = lodash_1.assign({}, form_1.baseInputs, {
    item: 'item',
});
var CardComponent = CardComponent_1 = (function (_super) {
    __extends(CardComponent, _super);
    function CardComponent(notification, asyncHelper, formService, guidService, parentForm, cardContainer) {
        var _this = _super.call(this, notification, asyncHelper, formService, guidService, parentForm) || this;
        _this.permanentFooter = false;
        // consumer properties
        _this.initCard = function () { return null; };
        _this.clickCard = function () { return null; };
        _this.cardContainer = cardContainer;
        _this.showContent$ = new rxjs_1.BehaviorSubject(false);
        return _this;
    }
    CardComponent.prototype.toggleContent = function () {
        if (this.showContent$.getValue()) {
            this.close();
        }
        else {
            this.open();
        }
    };
    CardComponent.prototype.open = function () {
        if (lodash_1.isFunction(this.initCard)) {
            this.initCard();
        }
        if (this.cardContainer.openCard()) {
            this.showContent$.next(true);
        }
    };
    CardComponent.prototype.close = function () {
        if (!this.showContent$.getValue()) {
            return true;
        }
        var canClose = true;
        //hack to stop auto save when non needed or available
        var obs = this.saveForm();
        if (obs) {
            canClose = !!this.submit();
        }
        if (canClose) {
            this.showContent$.next(false);
        }
        return canClose;
    };
    CardComponent.prototype.remove = function () {
        this.cardContainer.dataSource.remove(this.item);
    };
    CardComponent.prototype.saveForm = function () {
        return this.save(this.item);
    };
    CardComponent.prototype.getColumnTemplate = function (columnName) {
        return this.cardContainer.columnTemplates.filter(function (column) { return column.name === columnName; })[0];
    };
    return CardComponent;
}(form_1.FormComponent));
__decorate([
    core_1.Input(),
    __metadata("design:type", Boolean)
], CardComponent.prototype, "permanentFooter", void 0);
CardComponent = CardComponent_1 = __decorate([
    core_1.Component({
        selector: 'rlCard',
        template: require('./card.html'),
        inputs: [exports.cardInputs.item],
        providers: [
            {
                provide: form_1.FormComponent,
                useExisting: core_1.forwardRef(function () { return CardComponent_1; }),
            },
        ],
        changeDetection: core_1.ChangeDetectionStrategy.OnPush,
    }),
    __param(4, core_1.Optional()), __param(4, core_1.SkipSelf()),
    __param(5, core_1.Inject(core_1.forwardRef(function () { return cardContainer_1.CardContainerComponent; }))),
    __metadata("design:paramtypes", [__notification.NotificationService, async_service_1.AsyncHelper,
        form_service_1.FormService, typescript_angular_utilities_1.services.guid.GuidService, form_1.FormComponent,
        cardContainer_1.CardContainerComponent])
], CardComponent);
exports.CardComponent = CardComponent;
var CardComponent_1;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FyZC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbImNhcmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsc0NBQWtIO0FBQ2xILDZCQUFnRDtB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