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-family',
  templateUrl: './family.page.html',
  styleUrls: ['./family.page.scss'],
})
export class FamilyPage implements OnInit {

  tabs = 'members';
  suggestion_total:number=0;
  total_family:number = 0;
  family_active:number = 0;
  session_image_server:string='';
  curr_session:string='';


  constructor(
      private navctr: NavController,
      private router: Router,
      public sessionDataProviderService: SessionDataProviderService,
      private wrenchService: WrenchService
  ) {


  }
    member_uid:string='';
  ngOnInit() {
    this.member_uid=  this.sessionDataProviderService.member_uid
    this.getFamilyData();
    this.getFamilyPeningData();
    this.getFamilyActiveJobsData();
  }

  onBack() {
    this.navctr.back();
  }

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

  onEnroll() {
    this.router.navigate(['enroll']);
  }
  jobActive(item){
        this.router.navigate(['jobactive'],{state: item});
    }
  familyMemebr(item){
      var famItem = {jobManagerActiveData: this.jobManagerActiveData,
                                              familyPendingData:this.familyPendingData,
                                              itemData:item};
     this.router.navigate(['familymember'],{state: famItem});
  }

  usrData: {
    action:number, member_id: number, uid: string, sessionid: string, limit:20, page:1,offset: 0
  };
  familyTotalData:any;
  familyData: [];
  getFamilyData(){
    this.usrData = {action:22010,
      member_id: this.sessionDataProviderService.member_id,
      uid: this.sessionDataProviderService.member_uid,
      sessionid: this.sessionDataProviderService.session ,
      limit:20, page:1,offset: 0};
      this.curr_session =  this.sessionDataProviderService.session;

    this.wrenchService.getFamilyList(this.usrData).subscribe(
        familyTotalData => {
          this.familyTotalData = familyTotalData;
          console.log("FAMILY  RETURN->", this.familyTotalData);
          this.familyData = this.familyTotalData.result_list;
          // debugger;
            this.session_image_server = this.familyTotalData.session_image_server;
          console.log("FAMILY RETURN DATA->", this.familyData);
          this.total_family = this.familyData.length;
        }
    );

  }

  familyPendingTotalData:any;
  familyPendingData: [];
  getFamilyPeningData(){
    this.usrData = {action:22010,
      member_id: this.sessionDataProviderService.member_id,
      uid: this.sessionDataProviderService.member_uid,
      sessionid: this.sessionDataProviderService.session ,
      limit:20, page:1,offset: 0}

    this.wrenchService.getFamilyPeningList(this.usrData).subscribe(
        familyPendingTotalData => {
          this.familyPendingTotalData = familyPendingTotalData;
          console.log("familyPendingTotalData  RETURN->", this.familyPendingTotalData);
          this.familyPendingData = this.familyPendingTotalData.result_list;
          // debugger;
          console.log("FAMILY familyPendingData DATA->", this.familyPendingData);
          this.suggestion_total = this.familyPendingData.length;
        }
    );

  }

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

        this.wrenchService.getJobsManagerData(this.usrData).subscribe(
            jobManagerActiveTotalData => {
                this.jobManagerActiveTotalData = jobManagerActiveTotalData;
                console.log("jobManagerActiveTotalData  RETURN->", this.jobManagerActiveTotalData);
                this.jobManagerActiveData = this.jobManagerActiveTotalData.result_list;
                // debugger;
                console.log("jobManagerActiveTotalData RETURN DATA->", this.jobManagerActiveData);
                this.family_active = this.jobManagerActiveData.length;
            }
        );

    }

}
