import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Component, OnInit, ViewChild, ElementRef, Inject } from '@angular/core';

@Component({
  selector: 'app-register-scada',
  templateUrl: './register-scada.component.html',
  styleUrls: ['./register-scada.component.css']
})
export class RegisterScadaComponent implements OnInit {
  nombreSCADA: string;
  type: string;

  @ViewChild('regButton') register?: ElementRef;

  constructor(
    private _snackBar: MatSnackBar,
    @Inject(MAT_DIALOG_DATA) public data: any,
  ) { 
    this.nombreSCADA = "";
    this.type = "";
  }

  ngOnInit(): void {
    this.type = this.data.type;
    this.nombreSCADA = this.data.name;
  }

  validateName(){
    if(this.nombreSCADA == ""){
      this.openSnackBar('El nombre del SCADA no debe estar vacío');
    }else{
      this.register?.nativeElement.click();
    }
  }

  openSnackBar(msg: string){
    this._snackBar.open(msg, undefined, {
      duration: 2500,
    })
  }
}
