import { CommonModule } from '@angular/common';
import { EventEmitter, TemplateRef, ElementRef, Input, Output, ViewChild, Component, ViewEncapsulation, NgModule } from '@angular/core';
import { NtOverlayPosition, NtOverlayComponent, NtOverlayModule } from '@ng-tangram/components/overlay';
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;
};
let NtTooltipComponent = class NtTooltipComponent {
    constructor(_elementRef) {
        this._elementRef = _elementRef;
        this._title = '';
        this.position = NtOverlayPosition.Top;
        this.afterOpen = new EventEmitter();
        this.afterClosed = new EventEmitter();
        this.beforeOpen = new EventEmitter();
        this.beforeClosed = new EventEmitter();
        this.positionChange = new EventEmitter();
        this.origin = new CdkOverlayOrigin(_elementRef);
    }
    set title(value) { this._title = value; }
    get title() { return this._title; }
    set template(value) { this._template = value; }
    get template() { return this._template; }
    set tooltip(value) {
        if (value instanceof TemplateRef) {
            this._template = value;
        }
        else {
            this._title = value;
            this._template = null;
        }
    }
    get _isDirective() {
        const attributes = this._elementRef.nativeElement.attributes;
        return attributes && attributes['nt-tooltip'];
    }
    ngOnChanges(changes) {
        const change = changes.title || changes.template || changes.tooltip;
        if (change && !change.firstChange) {
            Promise.resolve().then(() => {
                this.overlay.forceUpdatePosition();
            });
        }
    }
    _afterOpen(event) {
        this.afterOpen.next(event);
    }
    _afterClosed(event) {
        this.afterClosed.next(event);
    }
    _beforeOpen(event) {
        this.beforeOpen.next(event);
    }
    _beforeClosed(event) {
        this.beforeClosed.next(event);
    }
    _positionChange(change) {
        this.positionChange.next(change);
    }
};
NtTooltipComponent.ctorParameters = () => [
    { type: ElementRef }
];
__decorate([
    Input()
], NtTooltipComponent.prototype, "title", null);
__decorate([
    Input()
], NtTooltipComponent.prototype, "template", null);
__decorate([
    Input('nt-tooltip')
], NtTooltipComponent.prototype, "tooltip", null);
__decorate([
    Input()
], NtTooltipComponent.prototype, "position", void 0);
__decorate([
    Output()
], NtTooltipComponent.prototype, "afterOpen", void 0);
__decorate([
    Output()
], NtTooltipComponent.prototype, "afterClosed", void 0);
__decorate([
    Output()
], NtTooltipComponent.prototype, "beforeOpen", void 0);
__decorate([
    Output()
], NtTooltipComponent.prototype, "beforeClosed", void 0);
__decorate([
    Output()
], NtTooltipComponent.prototype, "positionChange", void 0);
__decorate([
    ViewChild(NtOverlayComponent, { static: true })
], NtTooltipComponent.prototype, "overlay", void 0);
NtTooltipComponent = __decorate([
    Component({
        selector: 'nt-tooltip, [nt-tooltip]',
        template: "<ng-content></ng-content>\n<nt-overlay\n  overlayClass=\"nt-tootip-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  (overlayEnter)=\"overlay.markOpen()\"\n  (overlayLeave)=\"overlay.markClose()\"\n  (positionChange)=\"_positionChange($event)\">\n  <div class=\"nt-tooltip-content\" *ngIf=\"template\">\n    <ng-container *ngTemplateOutlet=\"template\"></ng-container>\n  </div>\n  <div class=\"nt-tooltip-content\" *ngIf=\"!template\" [innerHtml]=\"title\"></div>\n</nt-overlay>\n",
        encapsulation: ViewEncapsulation.None,
        host: {
            'class': 'nt-tooltip',
            '[class.nt-tooltip-trigger]': '!_isDirective',
            '(mouseenter)': 'overlay.markOpen()',
            '(mouseleave)': 'overlay.markClose()'
        }
    })
], NtTooltipComponent);

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;
};
let NtTooltipModule = class NtTooltipModule {
};
NtTooltipModule = __decorate$1([
    NgModule({
        imports: [CommonModule, NtOverlayModule],
        exports: [NtTooltipComponent],
        declarations: [NtTooltipComponent]
    })
], NtTooltipModule);

export { NtTooltipComponent, NtTooltipModule };
//# sourceMappingURL=tooltip.js.map
