import { Component, OnInit, EventEmitter, Output, Input, OnChanges } from '@angular/core';
import { PgEmployeeProjectDtlsEntity } from 'app/models/employee.model';
import { forEach } from '@angular/router/src/utils/collection';
import { environment } from '../../../../../environments/environment.dev';
@Component({
  selector: 'app-card-project-added',
  templateUrl: './card-project-added.component.html',
  styleUrls: ['./card-project-added.component.scss']
})
export class CardProjectAddedComponent implements OnInit, OnChanges {
  public projectDetails: Array<{ title: string; description: string; skills: Array<{ id: number, name: string }>; }>;
  @Output() navigation = new EventEmitter<{ page: string, data?: any }>();
  @Input() projects: PgEmployeeProjectDtlsEntity[];
  imageUrl: string = environment.imageUrl;
  constructor() {

  }
  ngOnChanges() {
    if (this.projects && this.projects.length > 0) {
      this.projectDetails = this.projects.map(project => {
        return {
          id: project.pgEmployeeProjectDtlsId,
          title: project.title,
          description: project.description,
          skills: project.pgprojectSkillsMapping.map(t => {
            return {
              id: t.pgSkillTrackDtls.pgSkillTrackMstr.skillTrackMstrId,
              name: t.pgSkillTrackDtls.pgSkillTrackMstr.skillTrackName
            };
          })
        };
      }).sort((a, b) => b.id - a.id);
    }
  }
  ngOnInit() {

  }
  assignNavigation(e) {
    e.data = Object.assign(e.data, { navigation: 'project-added' });
    this.navigation.emit(e);
  }
}
