/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
 */
import * as tslib_1 from "tslib";
import { Component, Input, ViewChild, EventEmitter, Output, HostListener } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { ControlContainer, NgForm } from '@angular/forms';
import { Subject } from 'rxjs/index';
import { throttleTime } from 'rxjs/operators';
var FVModalComponent = /** @class */ (function () {
    function FVModalComponent(modalService) {
        var _this = this;
        this.modalService = modalService;
        this.hideDebouncer = new Subject();
        this.onModalClose = new EventEmitter();
        this.subscriptions = [];
        this.subscriptions.push(this.modalService.onHidden.subscribe(function () { _this.hideDebouncer.next(); }));
        // Throttle for preventing executing same function 2+ times per 100ms
        this.subscriptions.push(this.hideDebouncer.pipe(throttleTime(200)).subscribe(function () { _this.doCheck(); }));
    }
    Object.defineProperty(FVModalComponent.prototype, "showModal", {
        set: /**
         * @param {?} show
         * @return {?}
         */
        function (show) {
            if (this._showModal !== show) {
                if (show === true) {
                    this.openModal();
                }
                else {
                    this.hideDebouncer.next();
                }
            }
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @param {?} event
     * @return {?}
     */
    FVModalComponent.prototype.onEsc = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        if (this.modalService.getModalsCount() > 1) {
            return;
        }
        if (!this.keyboardPrompt) {
            return;
        }
        if (event.keyCode === 27) {
            event.preventDefault();
        }
        /** @type {?} */
        var wnd = window.confirm('Are you sure you want to close the modal window?');
        if (this.modal && wnd) {
            this.closeModal();
        }
    };
    /**
     * @param {?=} timeout
     * @return {?}
     */
    FVModalComponent.prototype.doCheck = /**
     * @param {?=} timeout
     * @return {?}
     */
    function (timeout) {
        var _this = this;
        if (timeout === void 0) { timeout = 150; }
        setTimeout(function () {
            if (!_this.id) {
                return;
            }
            /** @type {?} */
            var elem = document.getElementById(_this.id);
            /** @type {?} */
            var newState = elem ? true : null;
            if (newState !== _this.oldState) {
                if (!newState) {
                    _this.closeModal();
                }
                _this.oldState = newState;
            }
        }, timeout);
    };
    /**
     * @return {?}
     */
    FVModalComponent.prototype.closeModal = /**
     * @return {?}
     */
    function () {
        if (this.modal) {
            this.modal.hide();
            this.onModalClose.emit(true);
            this.modal = undefined;
        }
    };
    /**
     * @return {?}
     */
    FVModalComponent.prototype.openModal = /**
     * @return {?}
     */
    function () {
        var _this = this;
        // To be sure that inputs have loaded
        setTimeout(function () {
            _this.modal = _this.modalService.show(_this.modalRef, {
                class: _this.modalClass || 'modal-lg',
                ignoreBackdropClick: true,
                keyboard: !_this.keyboardPrompt,
                backdrop: true,
            });
        }, 1);
    };
    /**
     * @return {?}
     */
    FVModalComponent.prototype.ngOnDestroy = /**
     * @return {?}
     */
    function () {
        this.closeModal();
        this.loading = true;
        this.onModalClose.emit(true);
        try {
            for (var _a = tslib_1.__values(this.subscriptions), _b = _a.next(); !_b.done; _b = _a.next()) {
                var subscription = _b.value;
                subscription.unsubscribe();
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_1) throw e_1.error; }
        }
        var e_1, _c;
    };
    FVModalComponent.decorators = [
        { type: Component, args: [{
                    selector: 'fv-modal',
                    template: "<ng-template #modalRef class=\"modal fade\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">\n  <div class=\"modal-content\" [attr.id]=\"id\">\n    <div class=\"modal-header\">\n      <h4 *ngIf=\"title\" class=\"modal-title pull-left\"> {{ title | ltranslate }}</h4>\n      <button type=\"button\" class=\"close pull-right modalBtn\" (click)=\"closeModal()\" aria-label=\"Close\">\n        <span aria-hidden=\"true\">&times;</span>\n      </button>\n    </div>\n    <div class=\"modal-body\">\n      <ng-content></ng-content>\n    </div>\n  </div>\n</ng-template>",
                    viewProviders: [{ provide: ControlContainer, useExisting: NgForm }],
                    styles: [".col{display:inline-flex;flex-basis:0;flex-grow:1;max-width:100%;min-width:50%}.col fv-form-tab{padding:0 5px;display:block;width:100%}.col fv-form-tab .controls-row{margin:0;padding:0}.col fv-form-tab div{max-width:100%}.columns-0,.columns-1{width:100%;min-width:100%;max-width:100%}.columns-2{width:50%;min-width:50%;max-width:50%}.columns-3{width:33.33%;max-width:33.33%;min-width:33.33%}.columns-4{width:25%;max-width:25%;min-width:25%}.controlBox .input-group{display:inline-flex;width:100%;margin-top:5px}.controlBox>.input-group>button:not(.input-group-addon),.controlBox>.input-group>input,.controlBox>.input-group>select{height:40px!important;width:100%;padding:10px}.controlBox .input-group button.input-group-addon{position:relative;width:35px;height:40px}.controlBox .input-group span.controlName{color:red}.controlBox .input-group button.input-group-addon i{position:absolute;top:10px;bottom:0;left:0;right:0}.has-text-centered,.table,.table thead th{text-align:center}.gridForm{width:100%;padding:0;margin:0 0 10px}.gridForm .input-group>.form-control{max-width:50%;border-radius:unset;margin-right:10px;min-width:80px;min-height:45px}.gridForm .input-group>.addon{background:0 0;border:none;color:#36c}.grid-table tbody>tr>td{vertical-align:middle}.modal-dialog>.modal-content{max-height:100vh}.modal-content>.modal-body{max-height:85vh;overflow-y:auto;padding-bottom:40px}.modal-content fv-navigator{display:block;height:50px;position:fixed;bottom:0;left:0;right:0;padding:0 3rem;background-color:#fdfdfd9e;border-bottom-right-radius:10px;border-bottom-left-radius:10px;margin:0 2px;z-index:999}.modal-content fv-navigator .docked-buttons{width:auto}.modal-content fv-navigator .btn-col:not(.bottom){max-width:unset;padding:6px!important}span.required{color:red}form:not(.ng-untouched) .ng-invalid{border:1px solid red},form:not(.ng-untouched) .ng-invalid.input-group-addon{border-left:none!important}span.error-block{color:red}@media screen and (max-width:426px){.columns-2,.columns-3,.columns-4{width:100%;max-width:100%;min-width:100%}}.tree:last-of-type(.accordion){margin:0}select:disabled{background:#eee}navigator-bot,navigator-top{display:flex}fv-menu-folder:last-of-type>accordion:last-of-type{margin:0;padding:0}.button-group>button:not(:last-child):not(:first-child){margin-left:0!important;padding-left:0!important;margin-right:0!important;padding-right:0!important}.fv_container,.fv_container>*,navigator-after,navigator-before{all:inherit!important;padding:0!important}.lookup-form .gridInputs{width:100%}.lookup-form .gridInputs select{width:40%}.lookup-form .gridInputs input{width:60%}.lookup-form .gridInputs,.lookup-form .gridInputs input,.lookup-form .gridInputs select{max-width:100%}.noMarginY{margin-top:0!important;margin-bottom:0!important}.placeholder,ng-select input:-moz-placeholder,ng-select input:-ms-input-placeholder,ng-select input:-webkit-input-placeholder,ng-select input:placeholder{color:#a9a9a9}select-dropdown>div{position:relative!important;top:0!important}select-dropdown div.options{text-align:left}.modal-dialog .modal-header .pull-right span{font-size:inherit!important}bs-datepicker-navigation-view{display:block;width:100%;text-align:center}.bs-datepicker-head .previous{float:left}.bs-datepicker-head .next{float:right}textarea{min-height:45px;min-width:100%}"]
                }] }
    ];
    /** @nocollapse */
    FVModalComponent.ctorParameters = function () { return [
        { type: BsModalService }
    ]; };
    FVModalComponent.propDecorators = {
        showModal: [{ type: Input }],
        keyboardPrompt: [{ type: Input }],
        loading: [{ type: Input }],
        title: [{ type: Input }],
        modalClass: [{ type: Input }],
        id: [{ type: Input }],
        onModalClose: [{ type: Output }],
        modalRef: [{ type: ViewChild, args: ['modalRef',] }],
        onEsc: [{ type: HostListener, args: ['window:keydown.esc', ['$event'],] }]
    };
    return FVModalComponent;
}());
export { FVModalComponent };
if (false) {
    /** @type {?} */
    FVModalComponent.prototype.hideDebouncer;
    /** @type {?} */
    FVModalComponent.prototype.keyboardPrompt;
    /** @type {?} */
    FVModalComponent.prototype.loading;
    /** @type {?} */
    FVModalComponent.prototype.title;
    /** @type {?} */
    FVModalComponent.prototype.modalClass;
    /** @type {?} */
    FVModalComponent.prototype.id;
    /** @type {?} */
    FVModalComponent.prototype.onModalClose;
    /** @type {?} */
    FVModalComponent.prototype.modalRef;
    /** @type {?} */
    FVModalComponent.prototype._showModal;
    /** @type {?} */
    FVModalComponent.prototype.modal;
    /** @type {?} */
    FVModalComponent.prototype.oldState;
    /** @type {?} */
    FVModalComponent.prototype.subscriptions;
    /** @type {?} */
    FVModalComponent.prototype.modalService;
}

//# sourceMappingURL=data:application/json;base64, 