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

@Component({
  selector: 'app-orders-add',
  templateUrl: './orders-add.component.html',
  styleUrls: ['./orders-add.component.scss']
})
export class OrdersAddComponent implements OnInit {
  public action: string = '';
  public assigns: any = [];

  constructor(private title: Title, public apiService: ApiService, public dialogRef: MatDialogRef<OrdersAddComponent>, @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.saveOrder(this.data).subscribe((data:any) => {
      if (data.res == "OK") {
        this.dialogRef.close();
      } else {
        this.apiService.showError(data.msg);
      }
    });
  }
  dismiss() {
    this.dialogRef.close();
  }

}
