import { Component, Injector, ViewChild, Input } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { EntityDtoOfInt64, UpdateShippingPackageInput, ShippingPackageServiceProxy } from '@shared/service-proxies/service-proxies';
import { ModalDirective } from 'ngx-bootstrap';
import { finalize } from 'rxjs/operators';

@Component({
    selector: 'updatePackageTypeModal',
    templateUrl: './update-packagetype-modal.component.html'
})
export class UpdatePackageTypeModalComponent extends AppComponentBase {

    @ViewChild('modalUpdate', {static: false}) modal: ModalDirective;

    saving = false;
    active = false;

    packageType : UpdateShippingPackageInput = new UpdateShippingPackageInput();

    constructor(
        injector: Injector,
        private _packageTypeService: ShippingPackageServiceProxy
    ) {
        super(injector);
    }

    show(packageType): void {
        this.packageType = packageType;
        this.active = true;
        this.modal.show();
    }

    onShown(): void {
      
    }

    save(): void {

        this.saving = true;

        this._packageTypeService.updateShippingPackage(this.packageType)
            .pipe(finalize(() => { this.saving = false; }))
            .subscribe(() => {
                this.notify.info(this.l('Saved Successfully'));
                this.close();
            });
    }

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