import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HyperService } from '../../core/services/http.service';
import { Router, NavigationEnd, RoutesRecognized } from "@angular/router";
import { LocalStorage } from '../../core/services/local_storage.service';
import * as moment from 'moment';
import { DomSanitizer, SafeResourceUrl, SafeUrl } from '@angular/platform-browser';
import { CONFIG } from '../../config';
import { filter, pairwise } from 'rxjs/operators';

@Component({
    selector: 'app-assessment-report',
    templateUrl: './assessment-report.component.html',
    styleUrls: ['./assessment-report.component.scss']
})
export class AssessmentReportComponent implements OnInit {
    sub: any;
    type: any;
    user_id: any;
    userData: any = {};
    user_info: any = [];
    loader: boolean;
    report_data: any;
    sales_date: any;
    page_load: boolean;
    excel_load: boolean;
    export_url: any;
    location_selected: any;
    selected_title: any = '';
    mymodel: string = "";
    _url: any;
    defaultValue: any;
    assessment_select: any = [];
    assessment_id: number;
    search_model: any = ''
    category: any = [{
        title: "Learning",
        id: "0"
    }]
    leader_type = [
        { title: "All", id: "0", is_selected: 0, sort_by: 0 },
        { title: "Dealer", id: "1", is_selected: 0, sort_by: 1 },
        { title: "Location", id: "2", is_selected: 0, sort_by: 2 },
        // { title: "AM", id: "3", is_selected: 0, sort_by: 3 },
        // { title: "RM", id: "4", is_selected: 0, sort_by: 4 },
        // { title: "ZM", id: "5", is_selected: 0, sort_by: 5 }
    ]
    sort_by: any;
    assessment_list: any;
    atype: number = 0;
    sendData: any = {};
    user_role: number;
    amuser_list: any = [];
    rmuser_list: any = [];
    zmuser_list: any = [];
    am_email: string = '';
    rm_email: string = '';
    zm_email: string = '';
    zm_zone: string;
    zm_zonename: string;
    total_item: number;
    page_per_size: number = 10;
    current_page: number;
    total_page: number;
    activeItem: number = -1;
    activePage: number = 1;
    page_count:number = 0;
    zmmail:string='';
    rmmail:string='';
    ammail:string='';
    cont: boolean;
    am_cont: boolean;
    previousUrl: string;
    zoneactive:boolean=false;
    rmInactive: boolean;
    amInactive: boolean;
    zmEmail: any;
    zmData:any;
    rmData:any;
    amData:any;
    setMenuId:string;
    tabRole:string;
    rmtabactive:boolean;
    total_score:any;
    constructor(private route: ActivatedRoute, private server: HyperService, private router: Router, private sanitizer: DomSanitizer) { }

    ngOnInit() {
       
        this.defaultValue = this.category[0];
        this.sub = this.route.params.subscribe(params => {
            this.type = params['type'];
            this.user_id = params['id'];
            this.userData.emailid = params['email'];
            this.rmmail = params['rmmail'];
            this.ammail = params['ammail'];
            this.zmmail = params['zmmail'];
        });
        this.router.events
            .pipe(filter((e: any) => e instanceof RoutesRecognized),
                pairwise()
            ).subscribe((e: any) => {
                console.log(e[0].urlAfterRedirects);
                this.previousUrl = e[0].urlAfterRedirects// previous url
                LocalStorage.setValue('previous_Url', this.previousUrl)
            });
        if (LocalStorage.getValue('previous_Url') != '/dashboard') {
            CONFIG.page_change = false;
            CONFIG.am_page_change = false;
        }
        this.current_page = 0;
        this.activePage = 0;
            if (this.type == "mobile") {
                LocalStorage.setValue('token', this.user_id)
                // LocalStorage.setValue('zmmail', this.zmmail)
                // LocalStorage.setValue('rmmail', this.rmmail)
                // LocalStorage.setValue('ammail', this.ammail)
                this.getuserdetails() //Get Authentication token
            } else {
                if(LocalStorage.getValue('user_data')!=undefined){
                    this.userData = LocalStorage.getValue('user_data');
                    this.user_role = LocalStorage.getValue('user_data').role;
                    // this.getZm();
                    if (this.user_role != undefined && this.user_role < 4) {
                        this.zm_email = "all";
                        this.rmmail = "all";
                        this.ammail = "all";
                        this.zmmail = "all";
                        this.getZm();
                    } else if (this.user_role != undefined && this.user_role < 6) {
                        this.rm_email = "all";
                        this.am_email = "all";
                        this.cont = (CONFIG.page_change) ? false : true;
                        this.getRm();
                    } else if (this.user_role != undefined && this.user_role < 7) {
                        this.am_email = "all";
                        this.am_cont = (CONFIG.am_page_change) ? false : true;
                        this.getAm();
                    } else {
                        this.am_email = this.userData.emailid
                        this.getAssessmentList()
                   }
                }

        }
        if(this.user_role<4){
            // this.setTab('1')
            this.setTab('5')
        }else if(this.user_role<6){
            this.setTab('2')
            // this.rmtabactive = false;
        }else if(this.user_role<7){
            this.setTab('3')
        }else{
            this.setTab('4')
        }
        
        this.location_selected = this.leader_type.filter(question => question.is_selected == 1);

    }
//pagination
public getServerData(event) {
    console.log(event)
    this.page_count = (event - 1);
    console.log('page', this.page_count)
    if (this.zm_email != undefined && this.zm_email != '' && this.rm_email == 'all' && this.am_email == 'all') {
        if(this.setMenuId=='4'){
            this.getAssessmentReport(this.assessment_id, this.page_count, "")
        }else{
            this.roleAssessmentReport(this.assessment_id, this.page_count, "zm");
        }
        
    } else if (this.rm_email != undefined && this.rm_email != '' && this.am_email == 'all') {
        if(this.setMenuId=='4'){
            this.getAssessmentReport(this.assessment_id, this.page_count, "rm")
        }else{
            this.roleAssessmentReport(this.assessment_id, this.page_count, "rm");
        }
    } else if (this.am_email != undefined && this.zm_email != 'all' && this.rm_email != 'all' && this.am_email != 'all') {
        if(this.setMenuId=='4'){
            this.getAssessmentReport(this.assessment_id, this.page_count, "am")
        }else{
            this.roleAssessmentReport(this.assessment_id, this.page_count, "am");
        }
    }
    this.onPageChange(event);
  }
  public onPageChange(event) {
    this.activeItem = -1;
    this.activePage = event;
    console.log('pagech', this.activePage)
  }
    //HO LOGGED
    getZm() {

        this.server.post("manager/zone", {})
            .then((data) => {
                if (data.status == 200 && data.result.response != 'failed' && data.result.data != null) {
                    console.log(data.result.data)
                    this.zmuser_list = data.result.data;
                    this.zmChange("all");
                } else if (data.result.status == 401 && data.result.response == 'failed') {
                    this.router.navigateByUrl('');
                }
            });
    }
    zmChange(event) {
        this.rm_email = "all";
        this.am_email = "all";
        if (event == "all") {
            this.rmInactive = true;
            this.amInactive = true;
            this.zm_email = "all";
            // LocalStorage.setValue("zmmail", this.zm_email)
        } else {
            this.rmInactive = false;
            this.amInactive = true;
            this.zm_email = event;
            if(this.setMenuId=='2'){
                this.rmInactive = true;
                this.amInactive = true;
              }
            // LocalStorage.setValue("zmmail", this.zm_email)
            // this.cont = (CONFIG.page_change) ? false : true;
            this.zm_zone = event.zone;
            this.zm_zonename = event.email;
            this.getRm();

        }
        if (this.zm_email == 'all') {
            this.zmEmail = 'all';
          } else {
            this.zmEmail = this.zm_zonename;
          }
         
        this.current_page = 0;
        this.activePage = 0;
       this.checkselectbox();
        
    }

    checkselectbox(){
        if(this.assessment_id != undefined){
            if (this.zm_email != undefined && this.zm_email != '' && this.rm_email == 'all' && this.am_email == 'all') {
                if(this.setMenuId=='4'){
                    this.getAssessmentReport(this.assessment_id, this.page_count, "")
                }else{
                    this.roleAssessmentReport(this.assessment_id, this.page_count, "zm");
                }
                
            } else if (this.rm_email != undefined && this.rm_email != '' && this.am_email == 'all') {
                if(this.setMenuId=='4'){
                    this.getAssessmentReport(this.assessment_id, this.page_count, "rm")
                }else{
                    this.roleAssessmentReport(this.assessment_id, this.page_count, "rm");
                }
            } else if (this.am_email != undefined && this.zm_email != 'all' && this.rm_email != 'all' && this.am_email != 'all') {
                if(this.setMenuId=='4'){
                    this.getAssessmentReport(this.assessment_id, this.page_count, "am")
                }else{
                    this.roleAssessmentReport(this.assessment_id, this.page_count, "am");
                }
            }else{
                if(this.setMenuId=='4'){
                    this.getAssessmentReport(this.assessment_id, this.page_count, "")
                }else{
                    this.roleAssessmentReport(this.assessment_id, this.page_count, "");
                }
            }
            console.log('if'); 
        }else{
            console.log('issf');
            this.getAssessmentList();
        }
    }
    // ZM LOGGED
    getRm() {
        this.amInactive = true;
        console.log(this.userData)
        this.server.post("manager/region", {
            zone: (this.user_role>3 && this.user_role!=5) ? this.userData.emailid : this.zm_zonename,
            zonename: (this.user_role>3 && this.user_role==5) ? this.userData.zone : this.zm_zone
        })
            .then((data) => {
                if (data.status == 200 && data.result.response != 'failed' && data.result.data != null) {
                    CONFIG.page_change = true;
                    this.rmuser_list = data.result.data;
                    if (this.user_role != undefined && this.user_role==4 || this.user_role==5) {
                        this.zmEmail = this.userData.emailid;
                        this.rmChange("all")
                      }
                } else if (data.result.status == 401 && data.result.response == 'failed') {
                    this.router.navigateByUrl('');
                }
            });
    }
    rmChange(event) {
        this.am_email = "all"
        if (event == "all") {
            this.amInactive = true;

        } else {
            this.amInactive = false;
            this.rm_email = event;
            if(this.setMenuId=='3'){
                this.amInactive = true;
              }

            // LocalStorage.setValue("rmmail", this.rm_email)
            // this.am_cont = (CONFIG.am_page_change) ? false : true;
            this.getAm();
        }
        this.current_page = 0;
        this.activePage = 0;
        this.checkselectbox();
    }

    // RM LOGGED
    getAm() {
        this.server.post("manager/area", {
            region: ((this.user_role<7 || this.user_role==14) && this.user_role!=6) ? this.rm_email : this.userData.emailid
        })
            .then((data) => {
                if (data.status == 200 && data.result.response != 'failed' && data.result.data != null) {
                    console.log(data.result.data)
                    CONFIG.am_page_change = true;
                    this.amuser_list = data.result.data;
                    if (this.user_role != undefined && this.user_role==6) {
                        this.setMenuId = '3';
                        this.amInactive = true;
                        this.rmInactive = true;
            
                        this.rm_email = this.userData.emailid;
                        this.amChange("all")
                      }
                } else if (data.result.status == 401 && data.result.response == 'failed') {
                    this.router.navigateByUrl('');
                }
            });
    }
    amChange(event) {
        this.am_email = event;
        // LocalStorage.setValue("ammail", this.am_email)
        this.current_page = 0;
        this.activePage = 0;
        this.checkselectbox();
    }
    getAssessmentList() {
        this.server.get("manager/assessmentlist?filter=atype:" + this.atype+',role:'+this.tabRole)
            .then((data) => {
                if (data.status == 200 && data.result.response != 'failed' && data.result.data != null) {
                    this.assessment_list = data.result.data;
                    if(this.assessment_list.length!=0){
                    // console.log(this.assessment_list[0])
                    this.assessment_select = this.assessment_list[0]
                    this.assessment_id = this.assessment_list[0].assessmentid
                    console.log(this.zm_email,this.rm_email,this.am_email)
                    if (this.zm_email != undefined && this.zm_email != '' && this.rm_email == 'all' && this.am_email == 'all') {
                        if(this.setMenuId=='4'){
                            //ho login
                            this.getAssessmentReport(this.assessment_id, this.page_count, "")
                        }else{
                            this.roleAssessmentReport(this.assessment_id, this.page_count, "zm");
                        }
                        
                    } 
                    // else if (this.zm_email != undefined && this.zm_email != ''&& this.zm_email == 'all' && this.rm_email == 'all' && this.am_email == 'all') {
                    //     if(this.setMenuId=='4'){
                    //         this.getAssessmentReport(this.assessment_id, this.page_count, "zm")
                    //     }else{
                    //         this.roleAssessmentReport(this.assessment_id, this.page_count, "zm");
                    //     }
                        
                    // } 
                    else if (this.rm_email != undefined && this.rm_email != '' && this.am_email == 'all') {
                        if(this.setMenuId=='4'){
                            this.getAssessmentReport(this.assessment_id, this.page_count, "rm")
                        }else{
                            this.roleAssessmentReport(this.assessment_id, this.page_count, "rm");
                        }
                    } else if (this.am_email != undefined && this.zm_email != 'all' && this.rm_email != 'all' && this.am_email != 'all') {
                        if(this.setMenuId=='4'){
                            this.getAssessmentReport(this.assessment_id, this.page_count, "am")
                        }else{
                            this.roleAssessmentReport(this.assessment_id, this.page_count, "am");
                        }
                    }else{
                        if(this.setMenuId=='4'){
                            this.getAssessmentReport(this.assessment_id, this.page_count, "")
                        }else{
                            this.roleAssessmentReport(this.assessment_id, this.page_count, "");
                        }
                    }
                    console.log(this.assessment_id)
                    }
                } else if (data.result.status == 401 && data.result.response == 'failed') {
                    this.router.navigateByUrl('');
                }
            });
    }


    getuserdetails() {
        this.loader = true
        this.updateMobileView();
    }
    updateMobileView(){
        this.server.get("user/profile").then((data) => {
            if (data.status == 200 && data.result.response != 'failed' && data.result.data != null) {
                this.userData = data.result.data;
                LocalStorage.setValue('user_data', this.userData)
                this.user_role = this.userData.role;
                if (this.user_role != undefined && this.user_role < 4) {
                    this.getZm();
                } else if (this.user_role != undefined && this.user_role < 6) {
                    this.cont = (CONFIG.page_change) ? false : true;
                    this.getRm();
                } else if (this.user_role != undefined && this.user_role < 7) {
                    this.am_cont = (CONFIG.am_page_change) ? false : true;
                    this.getAm();
                } else {
                    this.getAssessmentList()
               }
            }
            else if (data.result.status == 401 && data.result.response == 'failed') {
                this.router.navigateByUrl('');
            }
            else {
                alert("Oops something happened!");
            }
        })
    }

    getAssessmentReport(val,page,role) {
        console.log(role)
        if (this.selected_title == '') {
            this.sort_by = 0
        }
        if(role=="zm" && this.user_role==3){
          this._url = "manager/"+role+"assessmentreport?page="+page+"&limit=10&filter=sort:" + this.sort_by + "";
        }else if(this.user_role==7 || this.user_role==14 ||this.user_role==3 ){
          this._url = "manager/newassessmentreport/"+role+"?page="+page+"&limit=10&filter=sort:" + this.sort_by + "";
        } else if(this.user_role == 4 || this.user_role == 5 || this.user_role == 6){
          this._url = "manager/newassessmentreport/zm?page="+page+"&limit=10&filter=sort:" + this.sort_by + "";
        }else{
            this._url = "manager/"+role+"assessmentreport/"+role+"?page="+page+"&limit=10&filter=sort:" + this.sort_by + "";
          }

        this.loader = true
        this.server.post(this._url, {
            assessmentid: val,
            search: this.search_model,
            zmemail: this.zmEmail,
            rmemail: this.rm_email,
            amemail: (this.user_role < 7) ? this.am_email : (this.user_role == 14) ? this.userData.dealer.am_email : this.userData.emailid
        })
            .then((data) => {
                if (data.status == 200 && data.result.response != 'failed') {
                    setTimeout(() => {
                        this.loader = false
                        this.user_info = data.result.data;
                        this.total_item=data.result.total;
                        console.log('UserData', this.user_info)
                    }, 500);
                } else if (data.result.status == 401 && data.result.response == 'failed') {
                    this.router.navigateByUrl('');
                }
            });
    }
    clickExcelDownload() {
        console.log(this.zm_email,this.am_email,this.zm_zonename)
        if (this.zm_email == 'all') {
          this.zmData = 'all';
          this.rmData = 'all';
          this.amData = 'all';
          if(this.setMenuId=='4'){
            this.roleBasedExcel("zm")
          }else{
            this.tabWiseExcel('zm')
          }
         
          
        } else if (this.zm_email != undefined && this.zm_email != '' && this.zm_email != 'all' && this.rm_email == 'all' ) {
          this.zmData = this.zm_zonename;
          this.rmData = '';
          this.amData = '';
          if(this.setMenuId=='4'){
            this.roleBasedExcel("zm")
          }else{
            // this.tabWiseExcel('zm')
          }
          
        } else if (this.rm_email != undefined && this.rm_email != '' && this.am_email == 'all') {
          this.zmData = this.zm_zonename;
          this.rmData = this.rm_email;
          this.amData = '';
          if(this.setMenuId=='4'){
            this.roleBasedExcel("rm")
          }else{
            this.tabWiseExcel("rm")
          }
          
        } else if (this.am_email != undefined && this.zm_email != 'all' && this.rm_email != 'all' && this.am_email != 'all') {
          this.zmData = '';
          this.rmData = this.rm_email;
          this.amData = (this.user_role < 7) ? this.am_email : (this.user_role == 14) ? this.userData.dealer.am_email : this.userData.emailid;
          if(this.setMenuId=='4'){
            this.roleBasedExcel("am")
          }else{
            this.tabWiseExcel("am")
          }
          
        }
      }
      roleBasedExcel(role) {
          console.log('role excel')
        this.loader = true;
        this.excel_load = true;
        this._url = "managerexport/newassessmentreportexport/"+role+"?filter=sort:" + this.sort_by;
        this.server.post(this._url, {
          assessmentid: this.assessment_id,
          zmemail: this.zmData,
          rmemail: this.rmData,
          amemail: this.amData
        }).then((data) => {
          if (data.status == 200) {
            this.loader = false;
            this.export_url = (data.result.data);
            setTimeout(() => this.export_url = "", 1000);
            this.excelExport();
          } else {
            alert("error");
          }
        });
      }
      tabWiseExcel(role) {
          console.log(role,'tabbb')
        this.loader = true;
        this.excel_load = true;
        if(this.setMenuId=='1'){
            this._url = "managerexport/zmassessmentreport?filter=sort:" + this.sort_by;
        }else if(this.setMenuId=='2'){
            this._url = "managerexport/rmassessmentreport/"+role+"?filter=sort:" + this.sort_by;
        }else if(this.setMenuId=='3'){
            this._url = "managerexport/asmassessmentreport/"+role+"?filter=sort:" + this.sort_by;
        }else{
            this._url = "managerexport/newassessmentreportexport/"+role+"?filter=sort:" + this.sort_by
        }
        // this._url = "managerexport/newassessmentreportexport/"+role+"?filter=sort:" + this.sort_by;
        this.server.post(this._url, {
          assessmentid: this.assessment_id,
          zmemail: this.zmData,
          rmemail: this.rmData,
          amemail: this.amData
        }).then((data) => {
          if (data.status == 200) {
            this.loader = false;
            this.export_url = (data.result.data);
            setTimeout(() => this.export_url = "", 1000);
            this.excelExport();
          } else {
            alert("error");
          }
        });
      }

    excelExport() {
        return this.sanitizer.bypassSecurityTrustResourceUrl(this.export_url);
    }

    onSearchChange(searchValue: string) {
        this.search_model = searchValue;
        this.current_page = 0;
        this.activePage = 0;
        if (this.zm_email != undefined && this.zm_email != '' && this.rm_email == 'all' && this.am_email == 'all') {
            if(this.setMenuId=='4'){
                this.getAssessmentReport(this.assessment_id, this.page_count, "")
            }else{
                this.roleAssessmentReport(this.assessment_id, this.page_count, "zm");
            }
            
        } else if (this.rm_email != undefined && this.rm_email != '' && this.am_email == 'all') {
            if(this.setMenuId=='4'){
                this.getAssessmentReport(this.assessment_id, this.page_count, "rm")
            }else{
                this.roleAssessmentReport(this.assessment_id, this.page_count, "rm");
            }
        } else if (this.am_email != undefined && this.zm_email != 'all' && this.rm_email != 'all' && this.am_email != 'all') {
            if(this.setMenuId=='4'){
                this.getAssessmentReport(this.assessment_id, this.page_count, "am")
            }else{
                this.roleAssessmentReport(this.assessment_id, this.page_count, "am");
            }
        }else{
            if(this.setMenuId=='4'){
                this.getAssessmentReport(this.assessment_id, this.page_count, "")
            }else{
                this.roleAssessmentReport(this.assessment_id, this.page_count, "");
            }
        }
    }
    radioSelect(val) {
        for (let i = 0; i < this.leader_type.length; i++) {
            if (val == i) {
                this.leader_type[i].is_selected = 1;
                this.selected_title = this.leader_type[i].title
                this.sort_by = this.leader_type[i].sort_by
                console.log(this.selected_title)
            } else {
                this.leader_type[i].is_selected = 0;
            }
        }
        this.isLocationSelected()
    }

    isLocationSelected() {
        this.location_selected = this.leader_type.filter(question => question.is_selected == 1);
        this.current_page = 0;
        this.activePage = 0;
        if (this.zm_email != undefined && this.zm_email != '' && this.rm_email == 'all' && this.am_email == 'all') {
            if(this.setMenuId=='4'){
                this.getAssessmentReport(this.assessment_id, this.page_count, "zm")
            }else{
                this.roleAssessmentReport(this.assessment_id, this.page_count, "zm");
            }
            
        } else if (this.rm_email != undefined && this.rm_email != '' && this.am_email == 'all') {
            if(this.setMenuId=='4'){
                this.getAssessmentReport(this.assessment_id, this.page_count, "rm")
            }else{
                this.roleAssessmentReport(this.assessment_id, this.page_count, "rm");
            }
        } else if (this.am_email != undefined && this.zm_email != 'all' && this.rm_email != 'all' && this.am_email != 'all') {
            if(this.setMenuId=='4'){
                this.getAssessmentReport(this.assessment_id, this.page_count, "am")
            }else{
                this.roleAssessmentReport(this.assessment_id, this.page_count, "am");
            }
        }else{
            if(this.setMenuId=='4'){
                this.getAssessmentReport(this.assessment_id, this.page_count, "")
            }else{
                this.roleAssessmentReport(this.assessment_id, this.page_count, "");
            }
        }
    }

    categoryChange(val) {
        console.log(val.id)
        this.atype = val.id
        this.getAssessmentList()
    }
    assessmentChange(val) {
        console.log(val)
        this.assessment_id = val.assessmentid
        this.current_page = 0;
        this.activePage = 0;
        if (this.zm_email != undefined && this.zm_email != '' && this.rm_email == 'all' && this.am_email == 'all') {
            if(this.setMenuId=='4'){
                this.getAssessmentReport(this.assessment_id, this.page_count, "")
            }else{
                this.roleAssessmentReport(this.assessment_id, this.page_count, "zm");
            }
            
        } else if (this.rm_email != undefined && this.rm_email != '' && this.am_email == 'all') {
            if(this.setMenuId=='4'){
                this.getAssessmentReport(this.assessment_id, this.page_count, "rm")
            }else{
                this.roleAssessmentReport(this.assessment_id, this.page_count, "rm");
            }
        } else if (this.am_email != undefined && this.zm_email != 'all' && this.rm_email != 'all' && this.am_email != 'all') {
            if(this.setMenuId=='4'){
                this.getAssessmentReport(this.assessment_id, this.page_count, "am")
            }else{
                this.roleAssessmentReport(this.assessment_id, this.page_count, "am");
            }
        }else{
            if(this.setMenuId=='4'){
                this.getAssessmentReport(this.assessment_id, this.page_count, "")
            }else{
                this.roleAssessmentReport(this.assessment_id, this.page_count, "");
            }
        }
    }
    setTab(id){
        console.log('id'+id)
        this.setMenuId = id;
        this.zmData = '';
        // this.roleAssessmentReport(this.assessment_id, this.page_count, "zm");
        if(this.user_role==3){
            this.zoneactive = true;
            this.rmInactive = true;
            this.amInactive = true;
        }else{
            this.rmInactive = false; 
        }
        
        this.atype = 0;
        if(id=='1'){
            this.zoneactive = false;
            this.tabRole = 'ZM'
        }else if(id=='2'){
            this.tabRole = 'RM'
            if(this.user_role==4 || this.user_role==5){
                this.rmInactive = true;
            }
            // this.roleAssessmentReport(this.assessment_id, this.page_count, "zm");
        }else if(id=='3'){
            this.tabRole = 'AM'
            if(this.user_role==6){
                this.rmInactive = true;  
            }
            this.amInactive = true;
        }else if(id=='4'){
            if(this.user_role==6){
                this.rmInactive = true;
                this.amInactive = false;
            }
            this.tabRole = 'DSE'
        }
        else if(id=='5'){
            //trainer tab
            this.zoneactive = false;
            this.tabRole = 'TR'
        }
        if(this.user_role>7){
            this.zm_email='all';
            this.rm_email='all';
            this.am_email='all';
        }
        this.zm_email='all';
        this.zmEmail='all';
        this.rm_email='all';
        this.getAssessmentList()
    }

    roleAssessmentReport(val,page,role){
        console.log('role'+role+' '+this.setMenuId)
        if (this.selected_title == '') {
            this.sort_by = 0
        }
        // this.user_info=[]
        if(this.setMenuId=='1'){
            this._url = "manager/zmassessmentreport?page="+page+"&limit=10&filter=sort:" + this.sort_by + "";
        }else if(this.setMenuId=='2'){
            this._url = "manager/rmassessmentreport/"+role+"?page="+page+"&limit=10&filter=sort:" + this.sort_by + "";
        }else if(this.setMenuId=='3'){
            this._url = "manager/asmassessmentreport/"+role+"?page="+page+"&limit=10&filter=sort:" + this.sort_by + "";
        }
        else if(this.setMenuId=='5'){
            this._url = "manager/trainerassessmentreport"+"?page="+page+"&limit=10&filter=sort:" + this.sort_by + "";
        }
        
        this.loader = true
        this.server.post(this._url, {
            assessmentid: val,
            search: this.search_model,
            zmemail: this.zmEmail,
            rmemail: this.rm_email,
            amemail: (this.user_role < 7) ? this.am_email : (this.user_role == 14) ? this.userData.dealer.am_email : this.userData.emailid
        })
            .then((data) => {
                if (data.status == 200 && data.result.response != 'failed') {
                    setTimeout(() => {
                        this.loader = false
                        this.user_info = data.result.data;
                        this.total_item=data.result.total;
                        this.total_score=data.result.pass_score;
                        console.log('UserData', this.user_info,this.total_score)
                    }, 500);
                } else if (data.result.status == 401 && data.result.response == 'failed') {
                    this.router.navigateByUrl('');
                }
            });
    }
}
