import { Component, OnInit } from '@angular/core';
import { ContactService } from '../../../contact.service';
import {MdDialog, MdDialogRef, MD_DIALOG_DATA} from '@angular/material';
import { MyaccountComponent } from '../../../myaccount/myaccount.component';
import { Params,Router, ActivatedRoute, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';

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

  fs : any;
  ls : any;
  emailid : any;
  or : any;
  useridd :any;
  time :any;
  device_data:any;
  devicess:any;
  final:any;
  custtype:any;
  cust:boolean=false;
  Load : Boolean = false;
  date : any;
  devicesss:any;
  mb:any;
  logoutbut:boolean;
  dealer:boolean;
  text:any;
  option:any; 
  finall:any;
  Fromdate=new Date();
  todate= new Date();
  options=[];
  logo:any;
  before:any;

  superAdmin:Boolean = false;
  date1:any;


  constructor(private contactService: ContactService,private router: Router,public dialog: MdDialog) { }

  ngOnInit() {
  
    this.superAdmin = JSON.parse(window.atob(window.localStorage.token.split(".")[1])).isSuperAdmin;


    this.fs = JSON.parse(window.atob(window.localStorage.token.split(".")[1])).fn;
    this.ls = JSON.parse(window.atob(window.localStorage.token.split(".")[1])).ln;
    this.emailid = JSON.parse(window.atob(window.localStorage.token.split(".")[1])).email;
    this.or = JSON.parse(window.atob(window.localStorage.token.split(".")[1]))._orgName;
    this.useridd = JSON.parse(window.atob(window.localStorage.token.split('.')[1]))._id;
    this.mb =  JSON.parse(window.atob(window.localStorage.token.split('.')[1])).phn;
    this.custtype =  JSON.parse(window.atob(window.localStorage.token.split('.')[1])).isDealer;

    this.contactService.getDevice(this.emailid,this.useridd).subscribe(

      data => {
        this.devicesss = data
     
        this.finall = (this.devicesss.devices);

        for(let i=0;i<this.devicesss.devices.length;i++){

          // if(this.devicesss.devices[i].type_of_device =="Tracker"){

            let a ={
              value : this.devicesss.devices[i].Device_Name,
              viewValue:this.devicesss.devices[i].Device_Name,
              did:this.devicesss.devices[i].Device_ID,
              id:this.devicesss.devices[i]._id,
              user:this.devicesss.devices[i].user,
              // email: this.devicesss.devices[i].Email_ID,
              // deviceType: this.devicesss.devices[i].type_of_device
            }
            this.options.push(a);
          // }

        }
          // console.log(this.options);
      });

      if(this.custtype == true){
        this.cust = true;
      }  
      if(this.mb.charAt(0)=="n"){
        this.mb = ' '
      }


      if( window.localStorage['Custumer'] == 'ON'){
        this.logoutbut = false
        this.dealer = true
     }
     else{
         this.logoutbut = true
     }
          
     this.logo=window.localStorage['logo'];
     this.text=window.localStorage['text'];
       
  }

  ign(){
    this.router.navigateByUrl("device-report/ign-report");
  
  }

  ignition_report(){
    this.cond = false
    this.router.navigateByUrl("device-report/ignition_report");
  }

  group(){
    this.cond = false
    this.router.navigateByUrl("group_view");
  }



  vehicleRoute(){
    this.router.navigateByUrl("vehicleRoute");

  }

  dealerInfo(){
    this.cond = false
    this.router.navigateByUrl("dealerInfo");
  }


  notification(){
    this.cond = false
    this.router.navigateByUrl("notifications");
  }

  driverPerformance(){
    this.cond = false;
    this.router.navigateByUrl("device-report/Driver-performance");
  }


  ideal(){
    this.router.navigateByUrl("device-report/ideal-report");
  }
  geo(){
    this.router.navigateByUrl("geofencing");
    
  }
  myaccount(){
   
    let dialogRef = this.dialog.open(MyaccountComponent, {
      width: '903px',
      data: {}
    });
  
    dialogRef.afterClosed().subscribe(result => {
  
      if(result == "succ"){
        // console.log("Updated")
      }
  
    });
  }
openNav() {
  /*  document.getElementById("myNav").style.width = "100%";
*/
   this.router.navigateByUrl("location");

}
logout(){
  window.localStorage.clear();
  this.router.navigateByUrl("login");
}
devi(){
  this.router.navigateByUrl("dashboard");

}
soon(){
  this.router.navigateByUrl("const?_i="+window.localStorage.token);
  
}
new(){
  this.router.navigateByUrl("new");
  
}
cond:Boolean = false;
point : any = 0;
 a(){
  // console.log(this.point);
   if(this.point == 0){
    this.cond = true;
    this.point ++;
   }
 else if(this.point % 2 == 0){
  this.cond = true;
  this.point ++;
 }
 else{
   this.cond = false
   this.point ++;
 }

  
}
addcus(){
  this.router.navigateByUrl("add");
}
report(){
  this.cond = false
  this.router.navigateByUrl("device-report");

}
report_speed(){
  // console.log("report speed call")
  this.cond = false
  this.router.navigateByUrl("device-report/device-speed-report");
}
mydealer(){
  window.localStorage['token'] =  window.localStorage['Dealer_token'];
  localStorage.removeItem('devices');
  window.localStorage['DataUpdate'] = 'True';
  if(window.localStorage['DataLoaded'] = 'True'){
    window.localStorage['Custumer'] = 'OFF'
    this.router.navigateByUrl("add")
   // this.router.navigateByUrl("const?_status="+"OK");
  }
}

summaryReport(){

  this.cond = false
  this.router.navigateByUrl("device-report/summary-report");
}

geofancingReport(){
  this.cond = false
  this.router.navigateByUrl("device-report/geofancing");
}

overspeed(){
  this.cond = false
  this.router.navigateByUrl("device-report/overspeed");

}

routeViolation(){
  this.cond = false
  this.router.navigateByUrl("device-report/routeViolation");

}

stoppage_report(){
  this.cond = false
  this.router.navigateByUrl("device-report/stoppage_report");

}

trip_report(){
  this.cond = false
  this.router.navigateByUrl("device-report/trip_report");

}

distance_report(){
  this.cond = false
  this.router.navigateByUrl("device-report/distance_report");
}

alert_data=[];

alertreport(){
  this.cond = false

  this.router.navigateByUrl("device-report/alert_report");

}

alertReport(Fromdate,todate,option){
  // console.log("alert Details");
}


route_map(){
  this.router.navigateByUrl("routeMapping");

}




}
