import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { FormControl, Validators, FormGroup } from '@angular/forms';
import { EmployeeHttpService } from 'app/services/employee/employee-http.service';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
import { EmployeeCreateProjectComponent } from '../employee-create-project/employee-create-project.component';
import { Router } from '@angular/router';
import { environment } from '../../../../environments/environment.dev';
import { LocalStorageService } from 'angular-2-local-storage';
@Component({
  selector: 'app-employee-dashboard-header',
  templateUrl: './employee-dashboard-header.component.html',
  styleUrls: ['./employee-dashboard-header.component.scss']
})
export class EmployeeDashboardHeaderComponent implements OnInit {
  img_path: string;
  createProjectForm: FormGroup;
  error: boolean;
  errMsg: string;
  projectDetails: any;
  prjTemplate;
  isSuccess: boolean;
  isVisible: boolean;
  prjResult;
  config;
  gitUserDetail;
  currentUser;

  @Input() projectTechStacks;
  @Output() showResult = new EventEmitter<object>();
  @Output() getUpdatedResult = new EventEmitter();

  constructor(private employeeService: EmployeeHttpService, private dialog: MatDialog, private router: Router, protected localStorageService: LocalStorageService) {
    this.img_path = environment.imageUrl + '/assets/img/employee/newdashboard/';
    this.currentUser = this.localStorageService.get('userInfo');
    this.getGitUserDetail();
  }
  ngOnInit() {
    this.createProjectForm = new FormGroup({
      prjSeed: new FormControl('', Validators.required),
      prjName: new FormControl('', Validators.required),
      prjDesc: new FormControl('', Validators.required),
    });
    this.isSuccess = false;
    this.isVisible = false;
  }
  goHome() {
    this.router.navigate(['employee']);
  }
  getGitUserDetail() {
    this.employeeService.getGitUserDetail(this.currentUser.email).subscribe(resp => {
      this.gitUserDetail = resp;
       }, err => {
      console.log('Error on gett all TechStacks');
      });
  }

  openDialog() {
    const dialogRef = this.dialog.open(EmployeeCreateProjectComponent, {
    height: '675px',
    width: '650.53px',
    data: {projectTechStacks: this.projectTechStacks, gitUserDetail: this.gitUserDetail}
    });
    dialogRef.componentInstance.prjSubmitted.subscribe((result) => {
      this.showResult.emit(result);
      this.getUpdatedResult.emit();
    });
  }

}
