import { Component, Inject, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import {
  MatDialog,
  MatDialogRef,
  MAT_DIALOG_DATA,
} from '@angular/material/dialog';
import { USERInterface } from 'src/app/interfaces/user-interface';
import { IAMService } from 'src/app/services/iam/iam.service';

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

  formGroup: FormGroup;
  usuario_storage:USERInterface = JSON.parse(localStorage.getItem('TIMUSERENC')!);

  constructor(
    public dialogRef: MatDialogRef<any>,
    @Inject(MAT_DIALOG_DATA) public data: any
  ) {
    this.formGroup = this.createFormGroup();
  }
  ngOnInit(): void {
  }
  private createFormGroup() {
    if (this.data.accion == 'Registrar') {
      return new FormGroup({
        perfil: new FormControl('', Validators.required),
        id_usuario_registra: new FormControl(this.usuario_storage.IDUSUARIO),
      });
    } else {      
      return new FormGroup({
        id: new FormControl({ value: this.data.item.id, disabled: true}),
        perfil: new FormControl(this.data.item.perfil , Validators.required),
      });
    }
  }

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

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

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


}
