import { Component, OnInit } from '@angular/core';
import {NavController} from "@ionic/angular";
import {Router} from "@angular/router";
import { WrenchService } from 'src/app/services/wrench.service';
import {SessionDataProviderService} from "../../store/session-data-provider.service";


@Component({
  selector: 'app-jobmanager',
  templateUrl: './jobmanager.page.html',
  styleUrls: ['./jobmanager.page.scss'],
})
export class JobmanagerPage implements OnInit {

menuData:any;
  tabs = 'active';
  session_image_server:string='';
  curr_session:string='';
  constructor(
      private navctr: NavController,
      private router: Router,
      public sessionDataProviderService: SessionDataProviderService,
      private wrenchService: WrenchService
  ) {
    this.menuData  =  this.router.getCurrentNavigation().extras.state;
    switch(this.menuData?.card_type){
      case 'REVIEWJOB':
        this.tabs ='review';
        break;
      case 'PASTDUEJOB':
        this.tabs ='pastdue';
        break
    }
   // debugger;
  }

  ngOnInit() {
    this.curr_session =  this.sessionDataProviderService.session;
    this.getManagerJobsData("ACTIVE");
    this.getManagerJobsData("PASTDUE");
    this.getManagerJobsData("REVIEW");
  }

  onMyJobs(){
    this.router.navigate(['joblist']);
  }
  onBack() {
    this.navctr.back();
  }

  onMentor() {
    this.router.navigate(['mentor']);
  }

  onEnroll() {
    this.router.navigate(['enroll']);
  }
  total_active:number=0;
  total_pastdue:number=0;
  total_review:number=0;

  usrData: {
    action:number,
    member_id: number,
    uid: string,
    sessionid: string,
    job_mode:string,
    limit:20,
    page:1,
    offset: 0
  };


  jobManagerActiveTotalData:any;
  jobManagerActiveData: [];
  jobManagerPastDueData: [];
  jobManagerReviewData: [];
  getManagerJobsData(job_mode){
    this.usrData = {
      action:22010,
      member_id: this.sessionDataProviderService.member_id,
      uid: this.sessionDataProviderService.member_uid,
      sessionid: this.sessionDataProviderService.session ,
      job_mode: job_mode,
      limit:20,
      page:1,
      offset: 0
    }

    this.wrenchService.getJobsManagerData(this.usrData).subscribe(
        jobManagerTotalData => {
          this.jobManagerActiveTotalData = jobManagerTotalData;
          console.log("getManagerJobsData  RETURN->", this.jobManagerActiveTotalData);
          this.session_image_server = this.jobManagerActiveTotalData.session_image_server;
          // debugger;
          switch (job_mode){
            case "ACTIVE":
              this.jobManagerActiveData = this.jobManagerActiveTotalData.result_list;
              this.total_active = this.jobManagerActiveData?.length;
              break;
            case "PASTDUE":
              this.jobManagerPastDueData = this.jobManagerActiveTotalData.result_list;
              this.total_pastdue = this.jobManagerPastDueData?.length;
              break;
            case "REVIEW":
              this.jobManagerReviewData = this.jobManagerActiveTotalData.result_list;
              this.total_review = this.jobManagerReviewData?.length;
              break;
          }
          console.log("getManagerJobsData RETURN DATA->", this.jobManagerActiveData);
        }
    );
  }

  jobActive(item){
    this.router.navigate(['jobactive'],{state: item});
  }
  jobReview(item){
    this.router.navigate(['jobreview'],{state: item});
  }
  jobPastDue(item){
    this.router.navigate(['jobpastdue'],{state: item});
  }
  onMyPendingJobs(){
    this.router.navigate(['pendingoffers']);

  }
}
