import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { Title } from '@angular/platform-browser';
import { ApiService } from 'app/api.service';

@Component({
  selector: 'app-inventory-warehouse-add',
  templateUrl: './inventory-warehouse-add.component.html',
  styleUrls: ['./inventory-warehouse-add.component.scss']
})
export class InventoryWarehouseAddComponent implements OnInit {

  public action: string = '';

  constructor(private title: Title, public apiService: ApiService, public dialogRef: MatDialogRef<InventoryWarehouseAddComponent>, @Inject(MAT_DIALOG_DATA) public data: any) {

    if (this.data.type == 'add') {
      this.action = 'Agregar';
    }
    else if (this.data.type == 'edit') {
      this.action = 'Editar';
    }
  }

  ngOnInit() {

  }

  save() {
    this.apiService.saveWarehouse(this.data).subscribe((data:any) => {
      if (data.res == "OK") {
        this.apiService.showOk("Perfecto","Operación realizada con éxito");
        this.dialogRef.close();
      } else {
        this.apiService.showError("Error",data.msg);
      }
    });
  }
  dismiss() {
    this.dialogRef.close();
  }


}
