import { ContentObserver, ObserversModule } from '@angular/cdk/observers';
import { CommonModule } from '@angular/common';
import { InjectionToken, ElementRef, Inject, Component, ViewEncapsulation, EventEmitter, TemplateRef, Input, Output, ViewChild, NgModule } from '@angular/core';
import { NtOverlayPosition, NtOverlayComponent, NtOverlayModule } from '@ng-tangram/components/overlay';
import { NtDropdownModule } from '@ng-tangram/components/dropdown';
import { Subject } from 'rxjs';
import { CdkOverlayOrigin } from '@angular/cdk/overlay';

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_POPOVER_PARENT_COMPONENT = new InjectionToken('nt-popover-parent-component');
var NtPopoverPaneComponent = (function () {
    function NtPopoverPaneComponent(_contentObserver, _elementRef, _parent) {
        this._contentObserver = _contentObserver;
        this._elementRef = _elementRef;
        this._parent = _parent;
        this._contentChange = new Subject();
    }
    Object.defineProperty(NtPopoverPaneComponent.prototype, "contentChanged", {
        get: function () {
            return this._contentChange.asObservable();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtPopoverPaneComponent.prototype, "textContent", {
        get: function () {
            return (this._elementRef.nativeElement.textContent || '').trim();
        },
        enumerable: true,
        configurable: true
    });
    NtPopoverPaneComponent.prototype.ngAfterContentInit = function () {
        var _this = this;
        this._contentSubscription = this._contentObserver
            .observe(this._elementRef)
            .subscribe(function () { return _this._checkContentChange(); });
    };
    NtPopoverPaneComponent.prototype.ngOnDestroy = function () {
        if (this._contentSubscription) {
            this._contentSubscription.unsubscribe();
        }
    };
    NtPopoverPaneComponent.prototype._checkContentChange = function () {
        if (this._parent.overlay.opened) {
            this._parent.overlay.forceUpdatePosition();
        }
    };
    NtPopoverPaneComponent.ctorParameters = function () { return [
        { type: ContentObserver },
        { type: ElementRef },
        { type: undefined, decorators: [{ type: Inject, args: [NT_POPOVER_PARENT_COMPONENT,] }] }
    ]; };
    NtPopoverPaneComponent = __decorate([
        Component({
            selector: 'nt-popover-pane, [nt-popover-pane]',
            template: "\n    <ng-content></ng-content>\n  ",
            encapsulation: ViewEncapsulation.None
        }),
        __param(2, Inject(NT_POPOVER_PARENT_COMPONENT))
    ], NtPopoverPaneComponent);
    return NtPopoverPaneComponent;
}());

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 NtPopoverComponent = (function () {
    function NtPopoverComponent(_elementRef) {
        this._elementRef = _elementRef;
        this._title = '';
        this.position = NtOverlayPosition.Top;
        this.confirm = new EventEmitter();
        this.cancel = new EventEmitter();
        this.afterOpen = new EventEmitter();
        this.afterClosed = new EventEmitter();
        this.beforeOpen = new EventEmitter();
        this.beforeClosed = new EventEmitter();
        this.positionChange = new EventEmitter();
        this.origin = new CdkOverlayOrigin(this._elementRef);
    }
    NtPopoverComponent_1 = NtPopoverComponent;
    Object.defineProperty(NtPopoverComponent.prototype, "title", {
        get: function () { return this._title; },
        set: function (value) { this._title = value; },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtPopoverComponent.prototype, "template", {
        get: function () { return this._template; },
        set: function (value) { this._template = value; },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtPopoverComponent.prototype, "popover", {
        set: function (value) {
            if (value instanceof TemplateRef) {
                this._template = value;
            }
            else {
                this._title = value;
                this._template = null;
            }
        },
        enumerable: true,
        configurable: true
    });
    NtPopoverComponent.prototype._afterOpen = function (event) {
        this.afterOpen.next(event);
    };
    NtPopoverComponent.prototype._afterClosed = function (event) {
        this.afterClosed.next(event);
    };
    NtPopoverComponent.prototype._beforeOpen = function (event) {
        this.beforeOpen.next(event);
    };
    NtPopoverComponent.prototype._beforeClosed = function (event) {
        this.beforeClosed.next(event);
    };
    NtPopoverComponent.prototype._positionChange = function (change) {
        this.positionChange.next(change);
    };
    var NtPopoverComponent_1;
    NtPopoverComponent.ctorParameters = function () { return [
        { type: ElementRef }
    ]; };
    __decorate$1([
        Input()
    ], NtPopoverComponent.prototype, "title", null);
    __decorate$1([
        Input()
    ], NtPopoverComponent.prototype, "template", null);
    __decorate$1([
        Input('nt-popover')
    ], NtPopoverComponent.prototype, "popover", null);
    __decorate$1([
        Input()
    ], NtPopoverComponent.prototype, "position", void 0);
    __decorate$1([
        Output()
    ], NtPopoverComponent.prototype, "confirm", void 0);
    __decorate$1([
        Output()
    ], NtPopoverComponent.prototype, "cancel", void 0);
    __decorate$1([
        Output()
    ], NtPopoverComponent.prototype, "afterOpen", void 0);
    __decorate$1([
        Output()
    ], NtPopoverComponent.prototype, "afterClosed", void 0);
    __decorate$1([
        Output()
    ], NtPopoverComponent.prototype, "beforeOpen", void 0);
    __decorate$1([
        Output()
    ], NtPopoverComponent.prototype, "beforeClosed", void 0);
    __decorate$1([
        Output()
    ], NtPopoverComponent.prototype, "positionChange", void 0);
    __decorate$1([
        ViewChild(NtOverlayComponent, { static: true })
    ], NtPopoverComponent.prototype, "overlay", void 0);
    NtPopoverComponent = NtPopoverComponent_1 = __decorate$1([
        Component({
            selector: '[nt-popover]',
            template: "<ng-content></ng-content>\n<nt-overlay\n  overlayClass=\"nt-popover-overlay\"\n  arrow\n  [origin]=\"origin\"\n  [position]=\"position\"\n  (afterOpen)=\"_afterOpen($event)\"\n  (afterClosed)=\"_afterClosed($event)\"\n  (beforeOpen)=\"_beforeOpen($event)\"\n  (beforeClosed)=\"_beforeClosed($event)\"\n  (positionChange)=\"_positionChange($event)\">\n  <div class=\"nt-popover\">\n    <div class=\"nt-popover-title\" *ngIf=\"template\">\n      <ng-container *ngTemplateOutlet=\"template\"></ng-container>\n    </div>\n    <div class=\"nt-popover-title\" *ngIf=\"!template\" [innerHtml]=\"title\"></div>\n    <div class=\"nt-popover-pane\">\n      <ng-content select=\"nt-popover-pane\"></ng-content>\n    </div>\n  </div>\n</nt-overlay>\n",
            encapsulation: ViewEncapsulation.None,
            host: {
                '(click)': 'overlay.toggle()'
            },
            providers: [
                { provide: NT_POPOVER_PARENT_COMPONENT, useExisting: NtPopoverComponent_1 }
            ]
        })
    ], NtPopoverComponent);
    return NtPopoverComponent;
}());

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 NtPopoverModule = (function () {
    function NtPopoverModule() {
    }
    NtPopoverModule = __decorate$2([
        NgModule({
            imports: [CommonModule, ObserversModule, NtOverlayModule, NtDropdownModule],
            exports: [NtPopoverComponent, NtPopoverPaneComponent],
            declarations: [NtPopoverComponent, NtPopoverPaneComponent]
        })
    ], NtPopoverModule);
    return NtPopoverModule;
}());

export { NT_POPOVER_PARENT_COMPONENT, NtPopoverComponent, NtPopoverModule, NtPopoverPaneComponent };
//# sourceMappingURL=popover.js.map
