(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs'), require('rxjs/operators'), require('@angular/animations'), require('@angular/cdk/coercion'), require('@angular/cdk/keycodes'), require('@angular/cdk/overlay'), require('@angular/common'), require('@angular/core'), require('@ng-tangram/components/core')) :
    typeof define === 'function' && define.amd ? define('@ng-tangram/components/overlay', ['exports', 'rxjs', 'rxjs/operators', '@angular/animations', '@angular/cdk/coercion', '@angular/cdk/keycodes', '@angular/cdk/overlay', '@angular/common', '@angular/core', '@ng-tangram/components/core'], factory) :
    (global = global || self, factory((global.nt = global.nt || {}, global.nt.components = global.nt.components || {}, global.nt.components.overlay = {}), global.rxjs, global.rxjs.operators, global.ng.animations, global.ng.cdk.coercion, global.ng.cdk.keycodes, global.ng.cdk.overlay, global.ng.common, global.ng.core, global.nt.components.core));
}(this, (function (exports, rxjs, operators, animations, coercion, keycodes, overlay, common, core, core$1) { 'use strict';

    var __read = (this && this.__read) || function (o, n) {
        var m = typeof Symbol === "function" && o[Symbol.iterator];
        if (!m) return o;
        var i = m.call(o), r, ar = [], e;
        try {
            while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
        }
        catch (error) { e = { error: error }; }
        finally {
            try {
                if (r && !r.done && (m = i["return"])) m.call(i);
            }
            finally { if (e) throw e.error; }
        }
        return ar;
    };
    var _a;

    (function (NtOverlayPosition) {
        NtOverlayPosition["Bottom"] = "bottom";
        NtOverlayPosition["BottomLeft"] = "bottomLeft";
        NtOverlayPosition["BottomRight"] = "bottomRight";
        NtOverlayPosition["Top"] = "top";
        NtOverlayPosition["TopLeft"] = "topLeft";
        NtOverlayPosition["TopRight"] = "topRight";
        NtOverlayPosition["Left"] = "left";
        NtOverlayPosition["LeftTop"] = "leftTop";
        NtOverlayPosition["LeftBottom"] = "leftBottom";
        NtOverlayPosition["Right"] = "right";
        NtOverlayPosition["RightTop"] = "rightTop";
        NtOverlayPosition["RightBottom"] = "rightBottom";
    })(exports.NtOverlayPosition || (exports.NtOverlayPosition = {}));

    (function (NtOverlayOrientation) {
        NtOverlayOrientation["Vertical"] = "vertical";
        NtOverlayOrientation["Horizontal"] = "horizontal";
    })(exports.NtOverlayOrientation || (exports.NtOverlayOrientation = {}));
    var BOTTOM_LEFT = (_a = __read([
        getConnectionPositionPair('start', 'bottom', 'start', 'top'),
        getConnectionPositionPair('center', 'bottom', 'center', 'top'),
        getConnectionPositionPair('end', 'bottom', 'end', 'top'),
        getConnectionPositionPair('start', 'top', 'start', 'bottom'),
        getConnectionPositionPair('center', 'top', 'center', 'bottom'),
        getConnectionPositionPair('end', 'top', 'end', 'bottom'),
        getConnectionPositionPair('start', 'top', 'end', 'top'),
        getConnectionPositionPair('start', 'center', 'end', 'center'),
        getConnectionPositionPair('start', 'bottom', 'end', 'bottom'),
        getConnectionPositionPair('end', 'top', 'start', 'top'),
        getConnectionPositionPair('end', 'center', 'start', 'center'),
        getConnectionPositionPair('end', 'bottom', 'start', 'bottom')
    ], 12), _a[0]), BOTTOM_CENTER = _a[1], BOTTOM_RIGHT = _a[2], TOP_LEFT = _a[3], TOP_CENTER = _a[4], TOP_RIGHT = _a[5], LEFT_TOP = _a[6], LEFT_CENTER = _a[7], LEFT_BOTTOM = _a[8], RIGHT_TOP = _a[9], RIGHT_CENTER = _a[10], RIGHT_BOTTOM = _a[11];
    var NT_OVERLAY_POSITION_PAIRS = {
        bottom: [
            BOTTOM_CENTER, BOTTOM_LEFT, BOTTOM_RIGHT,
            TOP_CENTER, TOP_LEFT, TOP_RIGHT,
            RIGHT_CENTER, RIGHT_TOP, RIGHT_BOTTOM,
            LEFT_CENTER, LEFT_TOP, LEFT_BOTTOM
        ],
        bottomLeft: [
            BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT,
            TOP_LEFT, TOP_CENTER, TOP_RIGHT,
            RIGHT_CENTER, RIGHT_TOP, RIGHT_BOTTOM,
            LEFT_CENTER, LEFT_TOP, LEFT_BOTTOM
        ],
        bottomRight: [
            BOTTOM_RIGHT, BOTTOM_CENTER, BOTTOM_LEFT,
            TOP_RIGHT, TOP_CENTER, TOP_LEFT,
            RIGHT_CENTER, RIGHT_TOP, RIGHT_BOTTOM,
            LEFT_CENTER, LEFT_TOP, LEFT_BOTTOM
        ],
        top: [
            TOP_CENTER, TOP_LEFT, TOP_RIGHT,
            BOTTOM_CENTER, BOTTOM_LEFT, BOTTOM_RIGHT,
            LEFT_CENTER, LEFT_TOP, LEFT_BOTTOM,
            RIGHT_CENTER, RIGHT_TOP, RIGHT_BOTTOM
        ],
        topLeft: [
            TOP_LEFT, TOP_CENTER, TOP_RIGHT,
            BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT,
            LEFT_CENTER, LEFT_TOP, LEFT_BOTTOM,
            RIGHT_CENTER, RIGHT_TOP, RIGHT_BOTTOM
        ],
        topRight: [
            TOP_RIGHT, TOP_CENTER, TOP_LEFT,
            BOTTOM_RIGHT, BOTTOM_CENTER, BOTTOM_LEFT,
            LEFT_CENTER, LEFT_TOP, LEFT_BOTTOM,
            RIGHT_CENTER, RIGHT_TOP, RIGHT_BOTTOM
        ],
        left: [
            LEFT_CENTER, LEFT_TOP, LEFT_BOTTOM,
            TOP_LEFT, TOP_CENTER, TOP_RIGHT,
            BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT,
            RIGHT_CENTER, RIGHT_TOP, RIGHT_BOTTOM
        ],
        leftTop: [
            LEFT_TOP, LEFT_CENTER, LEFT_BOTTOM,
            TOP_LEFT, TOP_CENTER, TOP_RIGHT,
            BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT,
            RIGHT_TOP, RIGHT_CENTER, RIGHT_BOTTOM
        ],
        leftBottom: [
            LEFT_BOTTOM, LEFT_CENTER, LEFT_TOP,
            TOP_LEFT, TOP_CENTER, TOP_RIGHT,
            BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT,
            RIGHT_BOTTOM, RIGHT_CENTER, RIGHT_TOP
        ],
        right: [
            RIGHT_CENTER, RIGHT_TOP, RIGHT_BOTTOM,
            TOP_LEFT, TOP_CENTER, TOP_RIGHT,
            BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT,
            LEFT_CENTER, LEFT_TOP, LEFT_BOTTOM
        ],
        rightTop: [
            RIGHT_TOP, RIGHT_CENTER, RIGHT_BOTTOM,
            TOP_LEFT, TOP_CENTER, TOP_RIGHT,
            BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT,
            LEFT_TOP, LEFT_CENTER, LEFT_BOTTOM
        ],
        rightBottom: [
            RIGHT_BOTTOM, RIGHT_CENTER, RIGHT_TOP,
            TOP_LEFT, TOP_CENTER, TOP_RIGHT,
            BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT,
            LEFT_BOTTOM, LEFT_CENTER, LEFT_TOP
        ],
    };
    function getConnectionPositionPair(originX, originY, overlayX, overlayY) {
        return { originX: originX, originY: originY, overlayX: overlayX, overlayY: overlayY };
    }
    function getPositionClassName(pair) {
        return pair.originX + "-" + pair.originY + "-" + pair.overlayX + "-" + pair.overlayY;
    }
    function getPositionOrientation(position) {
        return Object.keys(NT_OVERLAY_POSITION_PAIRS).indexOf(position) > 5
            ? exports.NtOverlayOrientation.Horizontal
            : exports.NtOverlayOrientation.Vertical;
    }

    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 NtOverlayComponent = (function () {
        function NtOverlayComponent(_changeDetectorRef, location) {
            var _this = this;
            this._changeDetectorRef = _changeDetectorRef;
            this._destroy = new rxjs.Subject();
            this._debounceClose = new core.EventEmitter();
            this._positionChange = new core.EventEmitter();
            this._locationChanges = rxjs.Subscription.EMPTY;
            this._opened = false;
            this._markClosed = true;
            this._position = exports.NtOverlayPosition.BottomLeft;
            this._positionPairs = NT_OVERLAY_POSITION_PAIRS[this._position];
            this._paddingClass = getPositionClassName(this._positionPairs[0]);
            this._fixed = false;
            this._arrow = false;
            this._nospacing = false;
            this._overlayClass = '';
            this._backdrop = false;
            this.afterOpen = new core.EventEmitter();
            this.afterClosed = new core.EventEmitter();
            this.beforeOpen = new core.EventEmitter();
            this.beforeClosed = new core.EventEmitter();
            this.overlayEnter = new core.EventEmitter();
            this.overlayLeave = new core.EventEmitter();
            this.positionChange = new core.EventEmitter();
            this.keydownEvents = new core.EventEmitter();
            this._debounceClose
                .pipe(operators.debounceTime(100), operators.filter(function () { return _this._markClosed; }), operators.takeUntil(this._destroy))
                .subscribe(function () { return _this.close(); });
            this._positionChange
                .pipe(operators.filter(function (position) { return position !== _this._paddingClass; }), operators.takeUntil(this._destroy))
                .subscribe(function (position) { return _this._paddingClass = position; });
            if (location) {
                this._locationChanges = location.subscribe(function () { return _this.close(); });
            }
        }
        Object.defineProperty(NtOverlayComponent.prototype, "opened", {
            get: function () { return this._opened; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtOverlayComponent.prototype, "origin", {
            get: function () { return this._origin; },
            set: function (value) { this._origin = value; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtOverlayComponent.prototype, "position", {
            set: function (value) {
                if (value) {
                    this._position = value;
                    this._positionPairs = NT_OVERLAY_POSITION_PAIRS[value];
                }
                else {
                    this._position = exports.NtOverlayPosition.BottomLeft;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtOverlayComponent.prototype, "positionPairs", {
            get: function () { return this._positionPairs; },
            set: function (value) {
                this._positionPairs = coercion.coerceArray(value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtOverlayComponent.prototype, "paddingClass", {
            get: function () { return this._paddingClass; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtOverlayComponent.prototype, "fixed", {
            get: function () { return this._fixed; },
            set: function (value) {
                this._fixed = coercion.coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtOverlayComponent.prototype, "arrow", {
            get: function () { return this._arrow; },
            set: function (value) {
                this._arrow = coercion.coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtOverlayComponent.prototype, "nospacing", {
            get: function () { return this._nospacing; },
            set: function (value) {
                this._nospacing = coercion.coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtOverlayComponent.prototype, "overlayClass", {
            get: function () { return this._overlayClass; },
            set: function (value) {
                this._overlayClass = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtOverlayComponent.prototype, "backdrop", {
            get: function () { return this._backdrop; },
            set: function (value) {
                this._backdrop = coercion.coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        NtOverlayComponent.prototype.ngAfterViewInit = function () {
            var _this = this;
            this.cdkConnectedOverlay.attach
                .pipe(operators.take(1), operators.switchMap(function () { return _this.cdkConnectedOverlay.overlayRef.keydownEvents(); }), operators.takeUntil(this._destroy))
                .subscribe(function (event) {
                if (event.keyCode === keycodes.ESCAPE) {
                    _this.close();
                }
                _this.keydownEvents.next(event);
            });
            this.cdkConnectedOverlay.attach
                .pipe(operators.delay(0), operators.takeUntil(this._destroy))
                .subscribe(function () { return _this._subscribeOutsideClickEvent(); });
            this.cdkConnectedOverlay.detach
                .pipe(operators.takeUntil(this._destroy))
                .subscribe(function () { return _this._unsubscribeOutsideClickEvent(); });
        };
        NtOverlayComponent.prototype.ngOnChanges = function (changes) {
            var change = changes.position || changes.fixed || changes.positionPairs;
            if (change && !change.firstChange) {
                this._setPosition();
            }
        };
        NtOverlayComponent.prototype.ngOnDestroy = function () {
            this._destroy.next();
            this._destroy.complete();
            this._locationChanges.unsubscribe();
        };
        NtOverlayComponent.prototype.open = function () {
            this._opened = true;
            this._markClosed = false;
            this._changeDetectorRef.markForCheck();
        };
        NtOverlayComponent.prototype.close = function () {
            this._opened = false;
            this._markClosed = true;
            this._changeDetectorRef.markForCheck();
        };
        NtOverlayComponent.prototype.toggle = function () {
            this.opened ? this.close() : this.open();
        };
        NtOverlayComponent.prototype.markOpen = function () {
            this.open();
        };
        NtOverlayComponent.prototype.markClose = function () {
            this._markClosed = true;
            this._debounceClose.next();
        };
        NtOverlayComponent.prototype.forceUpdatePosition = function () {
            var _a;
            if (this.opened) {
                (_a = this.cdkConnectedOverlay.overlayRef) === null || _a === void 0 ? void 0 : _a.updatePosition();
            }
        };
        NtOverlayComponent.prototype.onAnimationStart = function (event) {
            if (event.toState === null) {
                this.beforeOpen.next();
            }
            else if (event.toState === 'void') {
                this.beforeClosed.next();
            }
        };
        NtOverlayComponent.prototype.onAnimationDone = function (event) {
            if (event.toState === null) {
                this.afterOpen.next();
            }
            else if (event.toState === 'void') {
                this.afterClosed.next();
            }
        };
        NtOverlayComponent.prototype.onOverlayPositionChange = function (event) {
            this._positionChange.next(getPositionClassName(event.connectionPair));
        };
        NtOverlayComponent.prototype._setPosition = function () {
            this._positionPairs = this.fixed ?
                this._positionPairs.slice(0, 1) :
                this._positionPairs;
            this._paddingClass = getPositionClassName(this._positionPairs[0]);
        };
        NtOverlayComponent.prototype._subscribeOutsideClickEvent = function () {
            var _this = this;
            if (!this._outsideClickSubscription) {
                this._outsideClickSubscription = core$1.fromOutsideClick([
                    this.cdkConnectedOverlay.overlayRef.overlayElement,
                    this.origin.elementRef.nativeElement
                ])
                    .pipe(operators.takeUntil(this._destroy))
                    .subscribe(function () { return _this.close(); });
            }
        };
        NtOverlayComponent.prototype._unsubscribeOutsideClickEvent = function () {
            if (this._outsideClickSubscription) {
                this._outsideClickSubscription.unsubscribe();
                this._outsideClickSubscription = null;
            }
        };
        NtOverlayComponent.ctorParameters = function () { return [
            { type: core.ChangeDetectorRef },
            { type: common.Location, decorators: [{ type: core.Optional }] }
        ]; };
        __decorate([
            core.Input()
        ], NtOverlayComponent.prototype, "origin", null);
        __decorate([
            core.Input()
        ], NtOverlayComponent.prototype, "position", null);
        __decorate([
            core.Input()
        ], NtOverlayComponent.prototype, "positionPairs", null);
        __decorate([
            core.Input()
        ], NtOverlayComponent.prototype, "fixed", null);
        __decorate([
            core.Input()
        ], NtOverlayComponent.prototype, "arrow", null);
        __decorate([
            core.Input()
        ], NtOverlayComponent.prototype, "nospacing", null);
        __decorate([
            core.Input()
        ], NtOverlayComponent.prototype, "overlayClass", null);
        __decorate([
            core.Input()
        ], NtOverlayComponent.prototype, "backdrop", null);
        __decorate([
            core.ViewChild(overlay.CdkConnectedOverlay, { static: true })
        ], NtOverlayComponent.prototype, "cdkConnectedOverlay", void 0);
        __decorate([
            core.Output()
        ], NtOverlayComponent.prototype, "afterOpen", void 0);
        __decorate([
            core.Output()
        ], NtOverlayComponent.prototype, "afterClosed", void 0);
        __decorate([
            core.Output()
        ], NtOverlayComponent.prototype, "beforeOpen", void 0);
        __decorate([
            core.Output()
        ], NtOverlayComponent.prototype, "beforeClosed", void 0);
        __decorate([
            core.Output()
        ], NtOverlayComponent.prototype, "overlayEnter", void 0);
        __decorate([
            core.Output()
        ], NtOverlayComponent.prototype, "overlayLeave", void 0);
        __decorate([
            core.Output()
        ], NtOverlayComponent.prototype, "positionChange", void 0);
        __decorate([
            core.Output()
        ], NtOverlayComponent.prototype, "keydownEvents", void 0);
        NtOverlayComponent = __decorate([
            core.Component({
                selector: 'nt-overlay, [nt-overlay]',
                template: "<ng-template\n  cdk-connected-overlay\n  [cdkConnectedOverlayOpen]=\"opened\"\n  [cdkConnectedOverlayHasBackdrop]=\"backdrop\"\n  [cdkConnectedOverlayPositions]=\"positionPairs\"\n  [cdkConnectedOverlayOrigin]=\"origin\"\n  (positionChange)=\"onOverlayPositionChange($event)\"\n  (backdropClick)=\"close()\">\n  <div class=\"nt-overlay-container {{paddingClass}} {{overlayClass}}\"\n    (mouseenter)=\"overlayEnter.emit($event)\"\n    (mouseleave)=\"overlayLeave.emit($event)\"\n    (click)=\"$event.stopPropagation()\"\n    [class.nospacing]=\"nospacing\"\n    [@fade]\n    (@fade.start)=\"onAnimationStart($event)\"\n    (@fade.done)=\"onAnimationDone($event)\">\n    <div class=\"nt-overlay-shadow\"></div>\n    <div class=\"nt-overlay-arrow\" *ngIf=\"arrow\"></div>\n    <div class=\"nt-overlay-pane\">\n      <ng-content></ng-content>\n    </div>\n  </div>\n</ng-template>\n",
                animations: [
                    animations.trigger('fade', [
                        animations.transition('void => *', core$1.fadeIn(.15)),
                        animations.transition('* => void', core$1.fadeOut(.15))
                    ])
                ],
                encapsulation: core.ViewEncapsulation.None,
                changeDetection: core.ChangeDetectionStrategy.OnPush
            }),
            __param(1, core.Optional())
        ], NtOverlayComponent);
        return NtOverlayComponent;
    }());

    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 NtOverlayModule = (function () {
        function NtOverlayModule() {
        }
        NtOverlayModule = __decorate$1([
            core.NgModule({
                imports: [common.CommonModule, overlay.OverlayModule],
                exports: [NtOverlayComponent],
                declarations: [NtOverlayComponent],
            })
        ], NtOverlayModule);
        return NtOverlayModule;
    }());

    exports.BOTTOM_CENTER = BOTTOM_CENTER;
    exports.BOTTOM_LEFT = BOTTOM_LEFT;
    exports.BOTTOM_RIGHT = BOTTOM_RIGHT;
    exports.LEFT_BOTTOM = LEFT_BOTTOM;
    exports.LEFT_CENTER = LEFT_CENTER;
    exports.LEFT_TOP = LEFT_TOP;
    exports.NT_OVERLAY_POSITION_PAIRS = NT_OVERLAY_POSITION_PAIRS;
    exports.NtOverlayComponent = NtOverlayComponent;
    exports.NtOverlayModule = NtOverlayModule;
    exports.RIGHT_BOTTOM = RIGHT_BOTTOM;
    exports.RIGHT_CENTER = RIGHT_CENTER;
    exports.RIGHT_TOP = RIGHT_TOP;
    exports.TOP_CENTER = TOP_CENTER;
    exports.TOP_LEFT = TOP_LEFT;
    exports.TOP_RIGHT = TOP_RIGHT;
    exports.getConnectionPositionPair = getConnectionPositionPair;
    exports.getPositionClassName = getPositionClassName;
    exports.getPositionOrientation = getPositionOrientation;

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

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