import { Router } from '@angular/router';
import { Component, OnInit } from '@angular/core';
import { WrenchService } from 'src/app/services/wrench.service';
import {SessionDataProviderService} from "../../store/session-data-provider.service";
import {WaitingInterestService} from "../../store/waiting-interest.service";
import {MarketDataService} from "../../store/market-data.service";
@Component({
  selector: 'app-my-course',
  templateUrl: './my-course.page.html',
  styleUrls: ['./my-course.page.scss'],
})
export class MyCoursePage implements OnInit {

  tabs: any = 'on';
  session_image_server:string='';
  curr_session:string='';

  constructor(
    private router: Router,
    public sessionDataProviderService: SessionDataProviderService,
    private wrenchService: WrenchService,
    public marketDataService:MarketDataService,
    private waitingInterestService:WaitingInterestService
  ) {
    this.marketDataService.getJobsData();
  }

  ionViewWillEnter(){
    console.log('Home page did enter - > ionViewWillEnter');
    this.session_image_server = this.marketDataService.session_image_server;
  }
  ngOnInit() {
    this.getJobsData();
  }

  onCourseDetail() {
    this.router.navigate(['course-detail']);
  }

  viewMarketItem(item) {
    this.router.navigate(['marketdetail'],{state: item});
  }

  ionViewDidEnter(){
    console.log('Home page did enter - > ionViewDidEnter ');
    this.session_image_server = this.marketDataService.session_image_server;
    this.jobsData =  this.marketDataService.jobsData;
  }

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

  jobsTotalData:any;
  jobsData: [];
 async getJobsData(){

    this.curr_session =  this.sessionDataProviderService.session;
    var interval = setInterval( ()=> {
      this.jobsData =  this.marketDataService.jobsData;
      this.session_image_server = this.marketDataService.session_image_server;
    }, 5000);


    // this.usrData = {action:11200, member_id: this.sessionDataProviderService.member_id, uid: this.sessionDataProviderService.member_uid, sessionid: this.sessionDataProviderService.session , limit:20, page:1}
    // this.wrenchService.getJobsData(this.usrData).subscribe(
    //     jobsTotalData => {
    //       this.jobsTotalData = jobsTotalData;
    //       console.log("PAH HX RETURN->", this.jobsTotalData);
    //       this.jobsData = this.jobsTotalData.result_list;
    //       this.session_image_server = this.jobsTotalData.session_image_server;
    //
    //       // debugger;
    //       console.log("JOBS RETURN DATA->", this.jobsData);
    //       //  this.blogDataService.setBlogData(this.blogResult.blog_data);
    //     }
    // );

  }
}
