import { Component, Inject, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatTableDataSource } from '@angular/material/table';
import { DetailsArtitle, InformationArtitle, ResponseFormDetails } from 'src/app/interfaces/acquisition-management/acquisition/artitle.interface';

@Component({
  selector: 'app-artitle-details.component',
  templateUrl: './artitle-details.component.html',
  styleUrls: ['./artitle-details.component.css']
})
export class ArtitleDetailsComponent implements OnInit {

  public displayedColumnsDetails: Array<string>;
  public dataSourceDetails: MatTableDataSource<DetailsArtitle>;

  constructor(
    private _dialogRef: MatDialogRef<any>,
    @Inject(MAT_DIALOG_DATA) public dataDialog: InformationArtitle
    ) {
    this.displayedColumnsDetails = ['NO','CODIGO','MODELO','CANTIDAD','PRECIO','CARACTERISTICAS','ESTADO','ACCIONES'];
    this.dataSourceDetails = new MatTableDataSource<DetailsArtitle>(this.dataDialog.DETAILS);
  }

  ngOnInit(): void {
  }

  public openDialog (type:string, elementData?: DetailsArtitle) {
    let obj:ResponseFormDetails = {} as ResponseFormDetails;
    if (type === 'CLOSE') {
      obj = {
        typeForm: type,
        element: this.dataDialog
      }
    } else if (type === 'FORM_DETAILS') {
      obj = {
        typeForm: type,
        element: this.dataDialog,
        itemElement: elementData
      }
    } else if (type === 'ELIM_DETAILS') {
      obj = {
        typeForm: type,
        element: this.dataDialog,
        itemElement: elementData
      }
    } else if (type === 'REST_DETAILS') {
      obj = {
        typeForm: type,
        element: this.dataDialog,
        itemElement: elementData
      }
    }

    this._dialogRef.close(obj);
  }

}

