import { Dialog } from '@angular/cdk/dialog';
import { Component, Inject, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatTableDataSource } from '@angular/material/table';
import { ReferencesData } from 'src/app/interfaces/acquisition-management/provider/provider.interface';
import { ContactProviderComponent } from '../contact-provider/contact-provider.component';
import { ReferencesFormComponent } from './references-form/references-form.component';

@Component({
  selector: 'app-references-provider',
  templateUrl: './references-provider.component.html',
  styleUrls: ['./references-provider.component.css']
})
export class ReferencesProviderComponent implements OnInit {
  public displayedColumns:Array<string>;
  public dataSource: MatTableDataSource<ReferencesData>;
  public isLoading: boolean;

  constructor(
    @Inject(MAT_DIALOG_DATA) public dataReferences: Array<ReferencesData>,
    private _dialogRef: MatDialogRef<any>
  ) {
    this.displayedColumns = [ 'EMPRESA', 'CORREO', 'TELEFONO', 'RFC', 'DIRECCION', 'ACCIONES' ];
    this.dataSource = new MatTableDataSource(this.dataReferences);
    this.isLoading = false;
  }

  ngOnInit(): void {
  }

  public openDialog(element:ReferencesData) {
    this._dialogRef.close(element);
  }

  public resizeText(text:string, numCaracteres:number){
    let contact:string = text.length > numCaracteres ? '...' : '';
    return text.substring(0, numCaracteres) + contact;
  }
}
