import { Component, ChangeDetectionStrategy, Input, Output, EventEmitter } from '@angular/core';
import { BehaviorSubject } from 'rxjs/Rx';
import { BundleService } from '../services/bundle-service';
// tslint:disable-next-line:component-class-suffix
var AddToBundleDialogContainer = (function () {
    function AddToBundleDialogContainer(bundleService) {
        this.bundleService = bundleService;
        this.hidden = false;
        this.close = new EventEmitter(false);
        this.cancel = new EventEmitter(false);
        this.errorMessage = new BehaviorSubject(null);
        this.bundlesLoaded = false;
    }
    AddToBundleDialogContainer.prototype.ngOnChanges = function (change) {
        if (change.hidden && !change.hidden.currentValue && !this.bundlesLoaded) {
            this.bundlesLoaded = true;
            this.bundleService.loadBundleStores();
        }
    };
    AddToBundleDialogContainer.prototype.addToBundle = function (bundle) {
        var _this = this;
        this.bundleService.addRuleToBundle(this.assetId, bundle).subscribe(function (result) {
            if (!result.errors) {
                _this.close.emit({ isCanceled: false });
                _this.bundlesLoaded = false;
                _this.errorMessage = null;
            }
            else {
                _this.errorMessage.next(result.errors);
            }
        });
    };
    return AddToBundleDialogContainer;
}());
export { AddToBundleDialogContainer };
AddToBundleDialogContainer.decorators = [
    { type: Component, args: [{
                changeDetection: ChangeDetectionStrategy.OnPush,
                selector: 'cw-add-to-bundle-dialog-container',
                template: "\n  <cw-add-to-bundle-dialog-component\n  [bundleStores]=\"bundleService.bundles$ | async\"\n  [hidden]=\"hidden\"\n  [errorMessage]=\"errorMessage | async\"\n  (cancel)=\"hidden = true; close.emit($event); errorMessage = null;\"\n  (addToBundle)=\"addToBundle($event)\"\n  ></cw-add-to-bundle-dialog-component>"
            },] },
];
/** @nocollapse */
AddToBundleDialogContainer.ctorParameters = function () { return [
    { type: BundleService, },
]; };
AddToBundleDialogContainer.propDecorators = {
    'assetId': [{ type: Input },],
    'hidden': [{ type: Input },],
    'close': [{ type: Output },],
    'cancel': [{ type: Output },],
};
//# sourceMappingURL=add-to-bundle-dialog-container.js.map