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

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

  public formGroup: FormGroup;

  constructor( @Inject(MAT_DIALOG_DATA) public descriptionRegister: string ) {
    this.formGroup = this.createFromGroup();
   }

  ngOnInit(): void {
  }

  private createFromGroup(): FormGroup {
    return new FormGroup({
      description: new FormControl( this.descriptionRegister, [Validators.required,Validators.minLength(10)]),
    });
  }

  public getErrorMessage(){
    if (this.description?.hasError('required')) {
      return 'Este campo es requerido';
    }else if(this.description?.hasError('minlength')){
      return 'Ingrese al menos 10 caracteres'
    }
    return "";
  }

  get description() { return this.formGroup.get('description'); }

}
