import { Component, OnInit } from '@angular/core';
import { MdDialog } from '@angular/material';
import { Router, ActivatedRoute } from '@angular/router';
import { ContactService } from '../contact.service';
import { DatainjectionService } from '../datainjection.service';
import { SidebarComponent } from '../sidebar/sidebar.component';
import { NotificationComponent } from '../notification/notification.component';

@Component({
  selector: 'app-poidetails',
  templateUrl: './poidetails.component.html',
  styleUrls: ['./poidetails.component.scss']
})
export class POIdetailsComponent implements OnInit {
  superAdmin: Boolean = false;
  fs: any;
  ls: any;
  cond: Boolean = false;
  point: any = 0;
  loading: any; loadingName: any;
  unloading: any; unloadingName: any;
  not_on_root: any; norName: any;
  address_show: string;
  deviceData: any;
  baba: any[];
  arrival_time: Date;
  Durations: string;
  status_toShow: string;
  lattitude: any;
  longitude: any;
  filtes: any;
  total_final: any;
  vehicleDetail: any;
  add_dev: boolean;
  textStatus: string;
  logo: any;
  text: any;
  emailid: any;
  or: any;
  mb: any;
  useridd: any;
  custtype: any;
  cust: Boolean = false;
  logoutbut: boolean;
  dealer: boolean;
  before:any;
  myInput:any;

  constructor(public dialog: MdDialog, private router: Router, private contactService: ContactService, private injectData: DatainjectionService, private activatedRoute: ActivatedRoute, private val: SidebarComponent, private inject: DatainjectionService, private notify: NotificationComponent) { }

  ngOnInit() {
       // this.superAdmin = JSON.parse(window.atob(window.localStorage.token.split(".")[1])).isSuperAdmin;
       var alpha = JSON.parse(window.atob(window.localStorage.token.split(".")[1]));
       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'];
  
     
  
  }

  myaccount() {
    this.cond = false
    this.router.navigateByUrl("accountSettings");

  }


  table1ch(){
    
    myFunction();
        function myFunction() {
          var input1, filter1, table, tr, td, i,td1;
          input1 = document.getElementById("myInput1");     
          filter1 = input1.value.toUpperCase();
          // console.log(filter1);
          table = document.getElementById("myTable1");
          tr = table.getElementsByTagName("tr");
          for (i = 0; i < tr.length; i++) {
            td = tr[i].getElementsByTagName("td")[1];
            td1= tr[i].getElementsByTagName("td")[0];       
            if (td) {
              if (td.innerHTML.toUpperCase().indexOf(filter1) > -1) {
                tr[i].style.display = "";               
              } 
              else if(td1.innerHTML.toUpperCase().indexOf(filter1) > -1){
                tr[i].style.display = "";
              
              }
              else {
                tr[i].style.display = "none";
              }
            }       
          }
        }
      }


      report(){
        this.cond = false
        this.router.navigateByUrl("device-report");
      
      }
      routeViolation(){
        this.cond = false
        this.router.navigateByUrl("device-report/routeViolation");
      
      }
      report_speed(){
        // console.log("report speed call")
        this.cond = false
        this.router.navigateByUrl("device-report/device-speed-report");
      }
      
      vehicleRoute(){
        this.cond = false
        this.router.navigateByUrl("vehicleRoute");
      }

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

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

      Ddetail(){
        this.router.navigateByUrl("driverdetail");
      }
      DModel(){
        this.router.navigateByUrl("deviceModel");
      }
      VType(){
        this.router.navigateByUrl("VehicleType");
      }
      
      alert_report(){
        this.cond = false
        this.router.navigateByUrl("device-report/alert-report");
      
      }

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

      devi(){
        this.router.navigateByUrl("dashboard");
      
      }

      openNav() {
        /*  document.getElementById("myNav").style.width = "100%";
      */
         this.router.navigateByUrl("location");
      
      }

      soon(){
        this.router.navigateByUrl("const?_i="+window.localStorage.token);
        
       }


       geo(){
        this.router.navigateByUrl("geofencing");
        
        }
      group(){
        this.cond = false
        this.router.navigateByUrl("group_view");
      }
      
      summaryReport(){
     
        this.cond = false
        this.router.navigateByUrl("device-report/summary-report");
      }
      
      overspeed(){
        this.cond = false
        this.router.navigateByUrl("device-report/overspeed");
      
      }
      
      notification(){
        this.cond = false
        this.router.navigateByUrl("notifications");
      }
      
      stoppage_report(){
        this.cond = false
        this.router.navigateByUrl("device-report/stoppage_report");
      
      }
      ignition_report(){
        this.cond = false
        this.router.navigateByUrl("device-report/ignition_report");
      }
      
      dealerInfo(){
        this.cond = false
        this.router.navigateByUrl("dealerInfo");
      }
      
      geofancingReport(){
        this.cond = false
        this.router.navigateByUrl("device-report/geofancing");
      }
      
      route_map(){
        this.router.navigateByUrl("routeMapping");
      
      }
      
      distance_report(){
      this.cond = false
      this.router.navigateByUrl("device-report/distance_report");
      }
      
      trip_report(){
        this.cond = false
        this.router.navigateByUrl("device-report/trip_report");
      
      }
      addcus(){
        localStorage.removeItem('mapLoad_ID')
        this.router.navigateByUrl("add");
      }
      
      addRoute(){
        this.cond = false
        this.router.navigateByUrl("vehicleRoute/setRoute");
      }

}
