import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';

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


  public formGroup: FormGroup;

  constructor() {
    this.formGroup = this.createFromGroup();
  }

  ngOnInit(): void {
  }

  // Creación de formulario de registro de módulos
  private createFromGroup(): FormGroup {
    return new FormGroup({
      proveedor: new FormControl('', Validators.required),
      correoElectronico: new FormControl('', [Validators.required, Validators.email]),
      telefono: new FormControl('', Validators.required),
      enlace: new FormControl('', Validators.required),
    });
  }

  public getErrorMessage() {
    if (this.proveedor?.hasError('required')) {
      return 'You must enter a value';
    }
    return ''
  }


  get proveedor() { return this.formGroup.get('proveedor'); }
  get correoElectronico() { return this.formGroup.get('correoElectronico'); }
  get telefono() { return this.formGroup.get('telefono'); }
  get enlace() { return this.formGroup.get('enlace'); }

}
