import { CommonModule } from '@angular/common';
import { EventEmitter, TemplateRef, ElementRef, Input, Output, ViewChild, Component, ViewEncapsulation, NgModule } from '@angular/core';
import { NtButtonModule } from '@ng-tangram/components/button';
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;
};
var NtPopConfirmComponent = (function () {
    function NtPopConfirmComponent(_elementRef) {
        this._elementRef = _elementRef;
        this._title = '';
        this.position = NtOverlayPosition.Top;
        this.confirmText = '确认';
        this.cancelText = '取消';
        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);
    }
    Object.defineProperty(NtPopConfirmComponent.prototype, "title", {
        get: function () { return this._title; },
        set: function (value) { this._title = value; },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtPopConfirmComponent.prototype, "template", {
        get: function () { return this._template; },
        set: function (value) { this._template = value; },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtPopConfirmComponent.prototype, "popconfirm", {
        set: function (value) {
            if (value instanceof TemplateRef) {
                this._template = value;
            }
            else {
                this._title = value;
                this._template = null;
            }
        },
        enumerable: true,
        configurable: true
    });
    NtPopConfirmComponent.prototype.ngOnChanges = function (changes) {
        var _this = this;
        var change = changes.title || changes.template || changes.popover;
        if (change && !change.firstChange) {
            Promise.resolve().then(function () {
                _this.overlay.forceUpdatePosition();
            });
        }
    };
    NtPopConfirmComponent.prototype._closeOverlay = function (event, isConfirm) {
        (isConfirm ? this.confirm : this.cancel).emit();
        this.overlay.close();
        event.stopPropagation();
    };
    NtPopConfirmComponent.prototype._afterOpen = function (event) {
        this.afterOpen.next(event);
    };
    NtPopConfirmComponent.prototype._afterClosed = function (event) {
        this.afterClosed.next(event);
    };
    NtPopConfirmComponent.prototype._beforeOpen = function (event) {
        this.beforeOpen.next(event);
    };
    NtPopConfirmComponent.prototype._beforeClosed = function (event) {
        this.beforeClosed.next(event);
    };
    NtPopConfirmComponent.prototype._positionChange = function (change) {
        this.positionChange.next(change);
    };
    NtPopConfirmComponent.ctorParameters = function () { return [
        { type: ElementRef }
    ]; };
    __decorate([
        Input()
    ], NtPopConfirmComponent.prototype, "title", null);
    __decorate([
        Input()
    ], NtPopConfirmComponent.prototype, "template", null);
    __decorate([
        Input('nt-popconfirm')
    ], NtPopConfirmComponent.prototype, "popconfirm", null);
    __decorate([
        Input()
    ], NtPopConfirmComponent.prototype, "position", void 0);
    __decorate([
        Input()
    ], NtPopConfirmComponent.prototype, "confirmText", void 0);
    __decorate([
        Input()
    ], NtPopConfirmComponent.prototype, "cancelText", void 0);
    __decorate([
        Output()
    ], NtPopConfirmComponent.prototype, "confirm", void 0);
    __decorate([
        Output()
    ], NtPopConfirmComponent.prototype, "cancel", void 0);
    __decorate([
        Output()
    ], NtPopConfirmComponent.prototype, "afterOpen", void 0);
    __decorate([
        Output()
    ], NtPopConfirmComponent.prototype, "afterClosed", void 0);
    __decorate([
        Output()
    ], NtPopConfirmComponent.prototype, "beforeOpen", void 0);
    __decorate([
        Output()
    ], NtPopConfirmComponent.prototype, "beforeClosed", void 0);
    __decorate([
        Output()
    ], NtPopConfirmComponent.prototype, "positionChange", void 0);
    __decorate([
        ViewChild(NtOverlayComponent, { static: true })
    ], NtPopConfirmComponent.prototype, "overlay", void 0);
    NtPopConfirmComponent = __decorate([
        Component({
            selector: '[nt-popconfirm]',
            template: "<ng-content></ng-content>\n<nt-overlay\n  overlayClass=\"nt-popconfirm-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-popconfirm\">\n    <div class=\"nt-popconfirm-title\" *ngIf=\"template\"><ng-container *ngTemplateOutlet=\"template\"></ng-container></div>\n    <div class=\"nt-popconfirm-title\" *ngIf=\"!template\" [innerHtml]=\"title\"></div>\n    <div class=\"nt-popconfirm-action\">\n      <button nt-button color=\"secondary\" size=\"tiny\" (click)=\"_closeOverlay($event, false)\">{{cancelText}}</button>\n      <button nt-button size=\"tiny\" (click)=\"_closeOverlay($event, true)\">{{confirmText}}</button>\n    </div>\n  </div>\n</nt-overlay>\n",
            encapsulation: ViewEncapsulation.None,
            host: {
                '(click)': 'overlay.toggle()'
            }
        })
    ], NtPopConfirmComponent);
    return NtPopConfirmComponent;
}());

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 NtPopConfirmModule = (function () {
    function NtPopConfirmModule() {
    }
    NtPopConfirmModule = __decorate$1([
        NgModule({
            imports: [CommonModule, NtOverlayModule, NtButtonModule],
            exports: [NtPopConfirmComponent],
            declarations: [NtPopConfirmComponent]
        })
    ], NtPopConfirmModule);
    return NtPopConfirmModule;
}());

export { NtPopConfirmComponent, NtPopConfirmModule };
//# sourceMappingURL=popconfirm.js.map
