import { Component, OnInit , ViewChild} from '@angular/core';
import { CONFIG } from '../../../app/config';
import { HyperService } from '../../core/services/http.service';
import { LocalStorage } from '../../core/services/local_storage.service';
import { ActivatedRoute,Router } from '@angular/router';

@Component({
  selector: 'app-taskstatus',
  templateUrl: './taskstatus.component.html',
  styleUrls: ['./taskstatus.component.scss']
})
export class TaskstatusComponent implements OnInit {
  today_personal_visit:any;
  today_personal_testride:any;
  today_personal_call:any;
  today_pending_visit:any;
  today_pending_testride:any;
  today_pending_call:any;


  tomorrow_personal_visit:any;
  tomorrow_personal_testride:any;
  tomorrow_personal_call:any;

  displaybottom:boolean=false;
  yearpresent:any='';
  monthpresent:any='';
  stage_testride:any;
  stage_booked:any;
  stage_invoiced:any;
  stage_lost:any;
  status_hot:any;
  status_warm:any;
  status_cold:any;
  displayboolean:boolean=false;
  href: string = "";
  today_enable:boolean=false;
  tommorrow_enable:boolean=false;
  more_enable:boolean=false;
  urlvalueobj:any='';
  yearvalueobj:any='';
  monthvalueobj:any='';
  testridecount:any='';
  constructor( private server: HyperService, private router: Router) { }
 

  
  public getmonthbaseddetails(year,month,urlvalue){
   // console.log("urlvalue--->",urlvalue);
    this.urlvalueobj=urlvalue;
    this.yearvalueobj=year;
    this.monthvalueobj=month;
    if(urlvalue == 'myenquiries'){
      this.displayboolean=false;
    }else{
      this.displayboolean=true;
    }
  //  console.log("getmonthbaseddetails--year->",year);
  //  console.log("getmonthbaseddetails--month->",month);
    this.getDashboardmonthbased(year,month);
  }
  ngOnInit() {
    this.today_enable=true;
    this.href = this.router.url;
   // console.log(this.router.url);

    // var year = CONFIG.configyearval;
    // var month = CONFIG.configmonthval;

    // console.log("year----->",year);
    // console.log("month----->",month);

  //  this.yearpresent=year;
  //  this.monthpresent=month;
    // this.route.params.subscribe(params => {
    // });

    
   

    this.getDashboardstatic();

    // if(this.urlvalueobj !=''){
    //   if(this.urlvalueobj == 'myenquiries'){
    //     this.displayboolean=false;
    //   }else{
    //     this.displayboolean=true;
    //   }
    // //  console.log("getmonthbaseddetails--year->",year);
    // //  console.log("getmonthbaseddetails--month->",month);
    //   this.getDashboardmonthbased(this.yearvalueobj,this.monthvalueobj);
    // }
    
  }
  //===
  getDashboardstatic() {
    this.server.get("enquiry/dashboard")
    .then((data) => {
        if (data.status == 200 && data.result.response != 'failed') {
       //   console.log(data.result.data.today.visit)
           this.today_personal_visit = data.result.data.today.visit;
           this.today_personal_testride = data.result.data.today.testride;
           this.today_personal_call = data.result.data.today.call;
           this.tomorrow_personal_visit=data.result.data.tomorrow.visit;
           this.tomorrow_personal_testride=data.result.data.tomorrow.testride;
           this.tomorrow_personal_call=data.result.data.tomorrow.call;
           //==
           this.today_pending_visit = data.result.data.pending.visit;
           this.today_pending_testride = data.result.data.pending.testride;
           this.today_pending_call = data.result.data.pending.call;
           

        }else if (data.result.status == 406 ) {
              //alert(data.result.message)
        }
         else if (data.result.status == 401 && data.result.response == 'failed') {}
    });
  }
  //==
  getDashboardmonthbased(year, month){
   

    // this.server.get("enquiry/enquirysales/2019/02")
    this.server.get("enquiry/enquirysales/" + year + "/" + month + "")
    .then((data) => {
        if (data.status == 200 && data.result.response != 'failed') {
          
          //  this.pending_tasks=data.result.data;
          // console.log(this.pending_tasks.enquiry.target);
          //==
          this.stage_testride=data.result.data.stage.testride;
          this.stage_booked=data.result.data.stage.booked;
          this.stage_invoiced=data.result.data.stage.postponed;
          this.stage_lost=data.result.data.stage.lost;
          //==
          this.status_hot=data.result.data.status.hot;
          this.status_warm=data.result.data.status.warm;
          this.status_cold=data.result.data.status.cold;
          this.testridecount=data.result.data.stage.testride;
          //==
          // this.getPercentage();
          // this.getPercentage_sales();
        }else if (data.result.status == 406 ) {
              //alert(data.result.message)
        }
         else if (data.result.status == 401 && data.result.response == 'failed') {}
    });
  }
  //==
  tasks_select(get_value){
    if(get_value==1){
      this.today_enable=true;
      this.tommorrow_enable=false;
      this.more_enable=false;
      this.getDashboardstatic();
    }else if(get_value==2){
      this.today_enable=false;
      this.tommorrow_enable=true;
      this.more_enable=false;
      this.getDashboardstatic();
    }else if(get_value==3){
      this.today_enable=false;
      this.tommorrow_enable=false;
      this.more_enable=true;
      this.router.navigateByUrl('task/datevalentered');
    }
  }
  todaysTask(tempvalue){
    //alert("tempvalue-->"+tempvalue)
   //  console.log("tempvalue---todaysTask>",tempvalue)
    this.router.navigateByUrl('task/'+tempvalue);
  }
  todaysTaskpending(tempvalue){
  //  console.log("tempvalue---todaysTaskpending>",tempvalue)
    this.router.navigateByUrl('task/'+tempvalue);
  }
  clicktestride(){
    //alert("33")
    this.router.navigateByUrl('testride');
  }
  clickplanner(){
    this.router.navigateByUrl('activityplanner');
  }
  clickenquirystage(tempvalue){
    this.router.navigateByUrl('enquiry-stage/'+tempvalue);
  }
  //==
  clickenquirystatus(tempvalue){
    this.router.navigateByUrl('enquiry-status/'+tempvalue);
  }
  tomorrowtask(tempvalue){
    this.router.navigateByUrl('task/'+tempvalue);
  }
  
}
