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

@Component({
  selector: 'app-config-order',
  templateUrl: './config-order.component.html',
  styleUrls: ['./config-order.component.css']
})
export class ConfigOrderComponent 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({
      despacho: new FormControl('', Validators.required),
      metodoPago: new FormControl('', Validators.required),
      propositoOrden: new FormControl('', Validators.required),
      actividad: new FormControl('', Validators.required),
      proyecto: new FormControl('', Validators.required),
    });
  }

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


  get despacho() { return this.formGroup.get('despacho'); }
  get metodoPago() { return this.formGroup.get('metodoPago'); }
  get propositoOrden() { return this.formGroup.get('propositoOrden'); }
  get actividad() { return this.formGroup.get('actividad'); }
  get proyecto() { return this.formGroup.get('proyecto'); }
}
