import { Component, OnInit } from '@angular/core';
import { CarouselConfig } from 'ngx-bootstrap/carousel';
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import {ContactService} from '../contact.service';
import { ViewChild, ElementRef } from '@angular/core';

@ViewChild('submitButton') 

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css'],
  providers: [{provide: CarouselConfig, useValue: {interval: 6050}}]
})
export class HomeComponent implements OnInit {
  items: Array<any> = []
  onSubmit(value:any){
    // console.log(value);
  }
  scrolldelay:any;
  first_name:any;
  last_name:any;
  email:any;
  phone:any;
  submitButton:ElementRef;
  demo:any;
  data_descip:any;
/* hello(a){
if(a == null){
  return false;
}
else{
  return true;
}
} */
  tost1(divid){
    if(divid == "dup_email"){
      this.data_descip = "We will contact you soon"
      launch_toast();
    }
    else if(divid == "email"){
      this.data_descip = "Please Enter either Email ID or Mobile Number"
      launch_toast();
    }
      function launch_toast() {
       // console.log(divid);
        var x = document.getElementById("toast")
        //console.log(x);
        x.className = "show";
        setTimeout(function(){ x.className = x.className.replace("show", ""); }, 4500);
    }
     }

  ToggleButton:any;
  dealerid:any;
  android:any;
  demorequest(){
    console.log(this.email,"this.email");

    if(this.email == null && this.phone == null){
      this.tost1("email");
    }
    else if(this.email == undefined && this.phone == undefined){
      this.tost1("email");
    }
    else{
      
      
        this.contact.demo(this.first_name,this.last_name,this.email,this.phone,this.dealerid).subscribe(   
          data => {
            this.demo = data 
            this.tost1("dup_email");
            this.first_name=" ";
            this.last_name=" ";
            this.email=undefined;
            this.phone=undefined;
          });
         
      
 
    
    }

  }
  constructor(private router: Router,private contact: ContactService,private contactService:ContactService) { 
/*  */
  }
  call(e) {
    {
           if (e.keyCode == 32) {
               e.preventDefault();
           }
       }
}
userData:any;
url:any;
iphone:any;
  ngOnInit() {

    this.dealerid =  window.localStorage['DealerID'];
    // console.log('dealerid',this.dealerid  );
    // this.android =  window.localStorage['android'];
    // // console.log(this.android)
    // this.iphone =  window.localStorage['iphone'];

    // if(window.localStorage.token){
    //   if( window.localStorage['Custumer'] == 'ON'){
    //     window.localStorage['token'] =  window.localStorage['Dealer_token'];
    //     window.localStorage['Custumer'] = 'OFF'
    //     this.router.navigateByUrl("const?_status="+"OK");
    //   }
    //   else{
    //     this.router.navigateByUrl("const?_status="+"OK");
    //   }
     
    // }
    // else{
  
    // }
    }
  }

