import { Component, OnInit } from '@angular/core';
import { BaseComponent } from '../base/base.component';
import { CvService } from '../services/cv.service';
import { ISideBar } from './side-bar.model';

@Component({
  selector: 'app-contact-sidebar',
  templateUrl: './contact-sidebar.component.html',
  styleUrl: './contact-sidebar.component.scss'
})
export class ContactSidebarComponent extends BaseComponent<ISideBar> implements OnInit {
  sideBarExpanded: boolean = false;
  displayName!: string;
  constructor(svc: CvService){
    super(svc);
  }
  
  ngOnInit(): void {
    this.svc.getCandidateInfoSubject.subscribe(() => {
      this.getCandidateAndSocialLinks();
    });
    this.getCandidateAndSocialLinks();
  }

  getCandidateAndSocialLinks(){
    this.svc.getCandidateWithSocialLinks(this.candidateId).subscribe((response: ISideBar) => {
      this.svc.candidateAndSocialLinks = this.svc.candidateAndSocialLinks ?? response;
      this.assignData(response);
    });
  }
}
