import { DatePipe } from '@angular/common';
import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { apiUrl } from 'src/app/_providers/_resources/api-url.properties';
import { AuthService } from 'src/app/_providers/_services/auth.service';
import { ErrorTranslateService } from 'src/app/_providers/_services/error-translate.service';
import { MasterService } from 'src/app/_providers/_services/master.service';
import { UiService } from 'src/app/_providers/_services/ui.service';

@Component({
  selector: 'app-user-approval',
  templateUrl: './user-approval.component.html',
  styleUrls: ['./user-approval.component.scss']
})
export class UserApprovalComponent {
 
  UserData: any;

  loading:boolean=false


  constructor(
    // private _menuService: MenuService,
    private router: Router,
    private _ui: UiService,
    // private emailService: EmailService,
    private authenticationService: AuthService,
    private _masterService: MasterService,
    private errorService:ErrorTranslateService,
    private datePipe: DatePipe,
    private route: ActivatedRoute,
    // private dialog: MatDialog
  ) {

  }

  ngOnInit() {
    this.getData();
    

  }

  getData(){
    this.loading=true;
    this._masterService.getMasterData(apiUrl.statusVerify).then((res) =>{
     
      this.UserData = res
      this.loading=false;

      
    })
  }

  navigateTo(destination: any) {
    this.router.navigate([destination])
  }


  goToDashboard(){
    this.navigateTo(`admin/dashboard`)
  }


  ApproveUser(user){

    let body = {
      userId :user.userId,
      status : 'A',
    }
    this.loading=true;

    this._masterService.saveMasterData(apiUrl.reqUser,body).then((res) =>{
       
      this.loading=false;

    this._ui.toastMessage(this.errorService.translate(res.msg));
    this.getData()


    })

  }
  RejectUser(user){

    let body = {
      userId :user.userId,
      status : 'R',
    }
    
    this.loading=true;

    this._masterService.saveMasterData(apiUrl.reqUser,body).then((res) =>{
      
      this.loading=false;

    this._ui.toastMessage(this.errorService.translate(res.msg));
    this.getData()
    })


  }

  downloadCmpProfile(cpFileName){
    this.loading=true;

    this._masterService.downloadFileWithAuth(apiUrl.cmpPrFileUpload,cpFileName).then(res=>{
     this.loading=false;

     

    })
  }

  downloadProjectCert(prCertFilename){
    this.loading=true;

    this._masterService.downloadFileWithAuth(apiUrl.projectCompleteCertFile,prCertFilename).then(res=>{
    this.loading=false;
   
    })

  }
}
