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

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

  public formGroup: FormGroup;

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

  ngOnInit(): void {
  }

  private createFromGroup(): FormGroup {
    return new FormGroup({
      familia: new FormControl(this.productoDetails.FAMILIA_ARTICULO, Validators.required),
      subfamilia: new FormControl(this.productoDetails.SUBFAMILIA_ARTICULO, Validators.required),
      articulo: new FormControl(this.productoDetails.MODELO_ARTICULO, Validators.required),
      modelo: new FormControl(this.productoDetails.MODELO_PRODUCTO, Validators.required),
      codigo: new FormControl(this.productoDetails.CODIGO_PRODUCTO, Validators.required),
      caracteristicas: new FormControl(this.productoDetails.CARACTERISTICAS_PRODUCTO, Validators.required),
      tipo: new FormControl(this.productoDetails.TIPO_ARTICULO, Validators.required),
      compraWeb: new FormControl(this.productoDetails.COMPRA_ARTICULO_WEB, Validators.required),
    });
  }

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

  get numeroArticulo() { return this.formGroup.get('numeroArticulo'); }
  get familia() { return this.formGroup.get('familia'); }
  get subfamilia() { return this.formGroup.get('subfamilia'); }
  get articulo() { return this.formGroup.get('articulo'); }
  get modelo() { return this.formGroup.get('modelo'); }
  get codigo() { return this.formGroup.get('codigo'); }
  get caracteristicas() { return this.formGroup.get('caracteristicas'); }
  get tipo() { return this.formGroup.get('tipo'); }
  get compraWeb() { return this.formGroup.get('compraWeb'); }

}
