import { Component, EventEmitter, Injector, ViewChild, Output } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { CreateRouteTemplateTypeInput, RouteTemplateTypeServiceProxy } from '@shared/service-proxies/service-proxies';
import { ModalDirective } from 'ngx-bootstrap';
import { PrimengTableHelper } from 'shared/helpers/PrimengTableHelper';
import { finalize } from 'rxjs/operators';

@Component({
    templateUrl: './create-route-template-types-modal.component.html',
    selector: 'createRouteTemplateTypeModal',
})
export class CreateRouteTemplateTypeModalComponent extends AppComponentBase {

   @ViewChild('createModal', {static: false}) modal: ModalDirective;
   @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();

    active = false;
    saving = false;
    routeTemplateType: CreateRouteTemplateTypeInput = new CreateRouteTemplateTypeInput();

     

    constructor(
        injector: Injector,
        private _routeTemplateTypeService: RouteTemplateTypeServiceProxy
    ) {
        super(injector);
    }

    show() {
        this.active = true;
        this.routeTemplateType.name = null;
        this.modal.show();
        
    }

    onShown(): void {
        //document.getElementById('cityInput').focus();
    }

    save(): void {
        this.saving = true;

        this._routeTemplateTypeService.createRouteTemplateType(this.routeTemplateType)
            .pipe(finalize(() => this.saving = false))
            .subscribe(() => { 
                this.notify.info(this.l('SavedSuccessfully'));
                this.close();
                this.modalSave.emit(null);
            });
    }

    close(): void {
        this.active = false;
        this.modal.hide();
    }
}
