import { Component, OnInit, Input, Output } from '@angular/core';
import { AuthService } from 'app/services/auth.service';
import { ToastsManager } from 'ng2-toastr/ng2-toastr'; 
import { environment } from '../../../../../environments/environment.dev';

@Component({
  selector: 'app-innovation-focals',
  templateUrl: './innovation-focals.component.html',
  styleUrls: ['./innovation-focals.component.scss']
})
export class InnovationFocalsComponent implements OnInit {

  innovList: boolean = true;
  addNewInnovation: boolean = false;
  innovRevs: any = [];
  img_path = environment.imageUrl+'/assets/img/Taflow/';
  inDetEdit: any;
  errMsg: string;
  idToDelete: number;
  dialogData: any;
  
  constructor(private AuthService: AuthService, private toastr: ToastsManager) { 
    this.getInnvoCats();
  }

  ngOnInit() {
    
    this.innovRevs = [
      {
        "category": "angular",
        "categoryId": 1,
        "error": {
          "code": "string",
          "message": "string"
        },
        "message": "created successfully",
        "reviewers": [
          {
            "fullName": "Ishtiaq Mohammed",
            "userEmail": "shuchita.rawat@altimetrik.com",
            "userInfoMstrId": 103
          },
          {
            "fullName": "Sabash L",
            "userEmail": "Sabash.Lakshmanan@altimetrik.com",
            "userInfoMstrId": 101
          }
        ]
      },
      {
        "category": "web",
        "categoryId": 2,
        "error": {
          "code": "string",
          "message": "string"
        },
        "message": "created successfully",
        "reviewers": [
          {
            "fullName": "Sabash L",
            "userEmail": "Sabash.Lakshmanan@altimetrik.com",
            "userInfoMstrId": 101
          },
          {
            "fullName": "Ishtiaq Mohammed",
            "userEmail": "shuchita.rawat@altimetrik.com",
            "userInfoMstrId": 103
          }
        ]
      },
      {
        "category": "java",
        "categoryId": 3,
        "error": {
          "code": "string",
          "message": "string"
        },
        "message": "created successfully",
        "reviewers": [
          {
            "fullName": "Nithya M",
            "userEmail": "userone@bnymellon.com",
            "userInfoMstrId": 102
          }
        ]
      },
      {
        "category": "devOps",
        "categoryId": 0,
        "error": {
          "code": "string",
          "message": "string"
        },
        "message": "created successfully",
        "reviewers": [
          {
            "fullName": "Yukesh G",
            "userEmail": "pgdemo2@bnymellon.com",
            "userInfoMstrId": 104
          },
          {
            "fullName": "Nithya M",
            "userEmail": "userone@bnymellon.com",
            "userInfoMstrId": 102
          }
        ]
      }
    ];

    this.dialogData = { title: 'Innovation Category Delete Confirmation', text: 'Would you like to delete this Category from the list?' };
  }
  getInnvoCats(){
    // this.AuthService.getInnovationCats().then(resp => {
    //   this.innovRevs = resp;
    //   console.log('resposne for all alvb -- ',this.innovRevs);
    // })
  }
  addInnvRv(){
    this.innovList = false;
    this.addNewInnovation = true;    
    this.errMsg = '';
  }

  editInnovRev(e){
    console.log(e);
    this.innovList = false;
    this.addNewInnovation = false;    
    this.errMsg = ''
    this.inDetEdit = e;
  }

  deleteInnovRev(e){
    console.log(e);
    if (e.isDelete) {
      document.getElementById("delIrConfModal").click();
      //this.confirmDelete
    }
    this.idToDelete = e.id;
  }
  confirmJrDelete() {
    console.log(this.idToDelete);
    this.AuthService.deleteInnovationCats(this.idToDelete).subscribe((resp:any) => {
      resp =  JSON.parse(resp._body);
      if (resp.status == 'error') {
        this.toastr.error(resp.message);
      } else {
        this.toastr.success(resp.successMessage);
        // this.getInnovationCats(); uncomment after API integration
      }
    })
  }

  formCancelled(e){
    console.log(e);
    this.innovList = true;
    this.getInnvoCats();
  }
}
