import { Component, Inject, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ReferencesData } from 'src/app/interfaces/acquisition-management/provider/provider.interface';

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

  public formGroupReferences: FormGroup;
  constructor(@Inject(MAT_DIALOG_DATA) public references:ReferencesData) {
    this.formGroupReferences = this.createFormGroup();
  }

  ngOnInit(): void {
  }

  private createFormGroup(){
    return new FormGroup({
      'EMPRESA': new FormControl(this.references.EMPRESA, Validators.required),
      'CORREO': new FormControl(this.references.CORREO,[ Validators.required, Validators.email]),
      'TELEFONO': new FormControl(this.references.TELEFONO, Validators.required),
      'RFC': new FormControl(this.references.RFC, [Validators.required, Validators.pattern(new RegExp(/^([A-ZÑ&]{3,4}) ?(?:- ?)?(\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])) ?(?:- ?)?([A-Z\d]{2})([A\d])$/))]),
      'DIRECCION': new FormControl(this.references.DIRECCION, Validators.required),
    });
  }

  get EMPRESA() { return this.formGroupReferences.get('EMPRESA'); }
  get CORREO() { return this.formGroupReferences.get('CORREO'); }
  get TELEFONO() { return this.formGroupReferences.get('TELEFONO'); }
  get RFC() { return this.formGroupReferences.get('RFC'); }
  get DIRECCION() { return this.formGroupReferences.get('DIRECCION'); }

}
