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

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

  ignition_data: any;
  fs : any;
  ls : any;
  emailid : any;
  before: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;
  superAdmin:Boolean = false;

  t:any;
  dataSelect: 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;


    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");
  }

  ideal(){
    this.router.navigateByUrl("device-report/ideal-report");
  }
  geo(){
    this.router.navigateByUrl("geofencing");
    
  }

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

  Ddetail(){
    this.router.navigateByUrl("driverdetail");
  }
  DModel(){
    this.router.navigateByUrl("deviceModel");
  }
  VType(){
    this.router.navigateByUrl("VehicleType");
  }
  
  
  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");

}

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

}
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");
}

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

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

}

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

}

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

}


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

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

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

}

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

}

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



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


fuel_report(Fdate,tdate,optionVal){

}

exportExcel(){
  
}


filterStates(val) {

  // console.log(val)
  // console.log(this.options)

  if (val) {
    const filterValue:any = val
     this.dataSelect = this.options.filter( function(d){
  
      return d.value.toLocaleLowerCase().indexOf(filterValue.toLocaleLowerCase()) > -1;    
    });
    return this.dataSelect;
  }

}

}
