import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { AgentesService } from '../../services/agentes.service';

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

  id: number = 0;
  agenteForm: FormGroup = this.formBuilder.group({
    nombre: [ '' ],
    detalles:  [ '' ]
  })

  constructor(
    private formBuilder: FormBuilder,
    private activateRoute: ActivatedRoute,
    private agenteService: AgentesService
  ){}

  ngOnInit(): void {
    this.id = this.activateRoute.snapshot.params['id'];
    this.llenarFormulario();
  }

  private llenarFormulario(){
    this.agenteService.getAgente(this.id).subscribe(
      res => {
        this.agenteForm.patchValue(res);
      },err => {
      }
    )
  }
}
