(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@angular/animations'), require('@angular/cdk/coercion'), require('@angular/common'), require('@ng-tangram/components/core')) :
    typeof define === 'function' && define.amd ? define('@ng-tangram/components/drawer', ['exports', '@angular/core', 'rxjs', 'rxjs/operators', '@angular/animations', '@angular/cdk/coercion', '@angular/common', '@ng-tangram/components/core'], factory) :
    (global = global || self, factory((global.nt = global.nt || {}, global.nt.components = global.nt.components || {}, global.nt.components.drawer = {}), global.ng.core, global.rxjs, global.rxjs.operators, global.ng.animations, global.ng.cdk.coercion, global.ng.common, global.nt.components.core));
}(this, (function (exports, core, rxjs, operators, animations, coercion, common, core$1) { '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 __param = (this && this.__param) || function (paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); }
    };
    var NT_DRAWER_CONTAINER = new core.InjectionToken('nt-drawer-container');
    var ANIMATION_TIMING = 0.4;
    var uniqueId = 0;
    var NtDrawerComponent = (function () {
        function NtDrawerComponent(_changeDetectorRef, _element, _renderer, _platformId, container) {
            this._changeDetectorRef = _changeDetectorRef;
            this._element = _element;
            this._renderer = _renderer;
            this._platformId = _platformId;
            this.id = "nt-drawer-" + uniqueId++;
            this._destory = new rxjs.Subject();
            this._backdrop = false;
            this._touchmode = false;
            this.state = 'closed';
            this.afterOpen = new core.EventEmitter();
            this.afterClosed = new core.EventEmitter();
            this.beforeOpen = new core.EventEmitter();
            this.beforeClosed = new core.EventEmitter();
            if (common.isPlatformBrowser(_platformId)) {
                this._initContainerAndStyles(container);
            }
            this._changePlacementValueAndStyle('left');
        }
        Object.defineProperty(NtDrawerComponent.prototype, "backdrop", {
            get: function () { return this._backdrop; },
            set: function (value) {
                this._backdrop = coercion.coerceBooleanProperty(value);
                if (this._backdrop) {
                    this._createBackdropOverlay();
                }
                else {
                    this._removeBackdropOverlay();
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtDrawerComponent.prototype, "placement", {
            get: function () { return this._placement; },
            set: function (value) {
                this._changePlacementValueAndStyle(value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtDrawerComponent.prototype, "touchmode", {
            get: function () { return this._touchmode; },
            set: function (value) {
                this._touchmode = coercion.coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        NtDrawerComponent.prototype.ngAfterViewInit = function () { };
        NtDrawerComponent.prototype.ngOnDestroy = function () {
            if (common.isPlatformBrowser(this._platformId)) {
                this._renderer.removeClass(this._container, this.id + "-container");
            }
            this._destory.next();
            this._destory.complete();
            this._unsubscribeOutsideActionEvent();
        };
        NtDrawerComponent.prototype.open = function () {
            this.state = this.placement;
        };
        NtDrawerComponent.prototype.close = function () {
            this.state = 'closed';
        };
        NtDrawerComponent.prototype.onAnimationDone = function (event) {
            if (event.fromState === 'void') {
                return;
            }
            if (event.toState !== 'closed') {
                this._subscribeOutsideActionEvent();
                this.afterOpen.emit();
            }
            else {
                this.afterClosed.emit();
            }
        };
        NtDrawerComponent.prototype.onAnimationStart = function (event) {
            if (event.fromState === 'void') {
                return;
            }
            if (event.toState === 'closed') {
                this._unsubscribeOutsideActionEvent();
                this._disattachBackdropOverlay();
                this.beforeClosed.emit();
            }
            else {
                this._attachBackdropOverlay();
                this.beforeOpen.emit();
            }
        };
        NtDrawerComponent.prototype._changePlacementValueAndStyle = function (placement) {
            if (this._placement) {
                this._renderer.removeClass(this._element.nativeElement, this._placement);
            }
            this._renderer.addClass(this._element.nativeElement, this._placement = placement);
        };
        NtDrawerComponent.prototype._initContainerAndStyles = function (container) {
            this._container = container ? container.element : document.body;
            if (this._container !== document.body) {
                this._renderer.addClass(this._element.nativeElement, 'nested');
            }
            this._renderer.addClass(this._container, this.id + "-container");
        };
        NtDrawerComponent.prototype._createBackdropOverlay = function () {
            this._backdropElement = this._renderer.createElement('div');
            this._renderer.addClass(this._backdropElement, 'nt-drawer-backdrop');
            this._renderer.addClass(this._backdropElement, this.id + "-backdrop");
        };
        NtDrawerComponent.prototype._removeBackdropOverlay = function () {
            this._disattachBackdropOverlay();
            this._backdropElement = null;
        };
        NtDrawerComponent.prototype._attachBackdropOverlay = function () {
            if (this.backdrop && this._backdropElement) {
                this._renderer.appendChild(this._container, this._backdropElement);
                this._renderer.addClass(this._container, 'nt-drawer-scrollblock');
            }
        };
        NtDrawerComponent.prototype._disattachBackdropOverlay = function () {
            if (this._backdropElement) {
                this._renderer.removeChild(this._container, this._backdropElement);
                this._renderer.removeClass(this._container, 'nt-drawer-scrollblock');
            }
        };
        NtDrawerComponent.prototype._subscribeOutsideActionEvent = function () {
            var _this = this;
            var outsideAction = this.touchmode ? core$1.fromOutsideTouch : core$1.fromOutsideClick;
            this._outsideActionSubscription = outsideAction([this._element.nativeElement], this._container)
                .pipe(operators.takeUntil(this._destory))
                .subscribe(function (_) { return _this.close(); });
        };
        NtDrawerComponent.prototype._unsubscribeOutsideActionEvent = function () {
            if (this._outsideActionSubscription) {
                this._outsideActionSubscription.unsubscribe();
                this._outsideActionSubscription = null;
            }
        };
        NtDrawerComponent.ctorParameters = function () { return [
            { type: core.ChangeDetectorRef },
            { type: core.ElementRef },
            { type: core.Renderer2 },
            { type: Object, decorators: [{ type: core.Inject, args: [core.PLATFORM_ID,] }] },
            { type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [NT_DRAWER_CONTAINER,] }] }
        ]; };
        __decorate([
            core.Input()
        ], NtDrawerComponent.prototype, "backdrop", null);
        __decorate([
            core.Input()
        ], NtDrawerComponent.prototype, "placement", null);
        __decorate([
            core.Input()
        ], NtDrawerComponent.prototype, "touchmode", null);
        __decorate([
            core.Output()
        ], NtDrawerComponent.prototype, "afterOpen", void 0);
        __decorate([
            core.Output()
        ], NtDrawerComponent.prototype, "afterClosed", void 0);
        __decorate([
            core.Output()
        ], NtDrawerComponent.prototype, "beforeOpen", void 0);
        __decorate([
            core.Output()
        ], NtDrawerComponent.prototype, "beforeClosed", void 0);
        NtDrawerComponent = __decorate([
            core.Component({
                selector: 'nt-drawer',
                template: "<ng-content></ng-content>",
                encapsulation: core.ViewEncapsulation.None,
                changeDetection: core.ChangeDetectionStrategy.OnPush,
                animations: [
                    animations.trigger('slide', [
                        animations.transition('closed => left', core$1.slideInLeft(ANIMATION_TIMING)),
                        animations.transition('closed => right', core$1.slideInRight(ANIMATION_TIMING)),
                        animations.transition('closed => top', core$1.slideInUp(ANIMATION_TIMING)),
                        animations.transition('closed => bottom', core$1.slideInDown(ANIMATION_TIMING)),
                        animations.transition('left => closed', core$1.slideOutLeft(ANIMATION_TIMING)),
                        animations.transition('right => closed', core$1.slideOutRight(ANIMATION_TIMING)),
                        animations.transition('top => closed', core$1.slideOutUp(ANIMATION_TIMING)),
                        animations.transition('bottom => closed', core$1.slideOutDown(ANIMATION_TIMING))
                    ])
                ],
                host: {
                    'class': 'nt-drawer',
                    '[class.opened]': 'state !== "closed"',
                    '[class.backdroped]': 'backdrop',
                    '[@slide]': 'state',
                    '(@slide.start)': 'onAnimationStart($event)',
                    '(@slide.done)': 'onAnimationDone($event)',
                }
            }),
            __param(3, core.Inject(core.PLATFORM_ID)),
            __param(4, core.Optional()), __param(4, core.Inject(NT_DRAWER_CONTAINER))
        ], NtDrawerComponent);
        return NtDrawerComponent;
    }());

    var __decorate$1 = (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 NtDrawerContainerDirective = (function () {
        function NtDrawerContainerDirective(_element) {
            this.element = _element.nativeElement;
        }
        NtDrawerContainerDirective_1 = NtDrawerContainerDirective;
        var NtDrawerContainerDirective_1;
        NtDrawerContainerDirective.ctorParameters = function () { return [
            { type: core.ElementRef }
        ]; };
        NtDrawerContainerDirective = NtDrawerContainerDirective_1 = __decorate$1([
            core.Directive({
                selector: '[nt-drawer-container]',
                providers: [
                    { provide: NT_DRAWER_CONTAINER, useExisting: NtDrawerContainerDirective_1 }
                ],
                host: {
                    'class': 'nt-drawer-container'
                }
            })
        ], NtDrawerContainerDirective);
        return NtDrawerContainerDirective;
    }());

    var __decorate$2 = (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 NtDrawerModule = (function () {
        function NtDrawerModule() {
        }
        NtDrawerModule = __decorate$2([
            core.NgModule({
                imports: [
                    common.CommonModule
                ],
                exports: [
                    NtDrawerComponent,
                    NtDrawerContainerDirective
                ],
                declarations: [
                    NtDrawerComponent,
                    NtDrawerContainerDirective
                ]
            })
        ], NtDrawerModule);
        return NtDrawerModule;
    }());

    exports.NT_DRAWER_CONTAINER = NT_DRAWER_CONTAINER;
    exports.NtDrawerComponent = NtDrawerComponent;
    exports.NtDrawerContainerDirective = NtDrawerContainerDirective;
    exports.NtDrawerModule = NtDrawerModule;

    Object.defineProperty(exports, '__esModule', { value: true });

})));
//# sourceMappingURL=drawer.umd.js.map
