import { HttpClient } from '@angular/common/http';
import { Component, OnInit, ViewChild } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { Table } from 'primeng/table';
import { BehaviorSubject, Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { AppBreadcrumbService } from 'src/app/app.breadcrumb.service';
import { Candidate } from 'src/app/shared/models/candidate';
import { candidatListService } from './candidat-list.service';

@Component({
  selector: 'app-candidat-list',
  templateUrl: './candidat-list.component.html',
  styleUrls: ['./candidat-list.component.scss']
})
export class CandidatListComponent implements OnInit {
    isEdit: boolean = false;
    candidates: Observable<Candidate[]>;
    candidate: Candidate;
    constructor(private breadcrumbService: AppBreadcrumbService,private http: HttpClient, private candidatListService: candidatListService, private route: ActivatedRoute) {
      this.breadcrumbService.setItems([
        { label: 'Candidats' },
        { label: 'List', routerLink: ['/candidat/candidat-list'] }
      ]);
  }

  ngOnInit() {
    this.route.data.subscribe((data: { candidats: Observable<Candidate[]> }) => this.candidates = data.candidats);
    this.candidates = this.candidatListService.getCandidats();
  }
  show(candidateUI: Candidate){
   // this.route.navigate(); // navigate to other page
    this.isEdit = true;
    this.candidate = new Candidate()
    this.candidate.id = candidateUI.id;
    this.candidate.firstName = candidateUI.firstName;
    this.candidate.lastName = candidateUI.lastName;
    this.candidate.emails = candidateUI.emails;
    
  }
}
