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

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

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

  ngOnInit() {
    this.getFamilySuggestList();
  }

  usrData: {
    action:number, member_id: number, uid: string,
    sessionid: string,
    'limit': 30,
    'offset': 0
  };

  familySuggestResult:any;
  familySuggestData:any;
  suggested_count:number  = 0;
  getFamilySuggestList(){
    this.usrData = {
      action:13010,
      member_id: this.sessionDataProviderService.member_id,
      uid: this.sessionDataProviderService.member_uid,
      sessionid: this.sessionDataProviderService.session,
      'limit': 30,
      'offset': 0
    };
    this.wrenchService.familySuggestList(this.usrData).subscribe(
        familySuggestResult => {
          this.familySuggestResult = familySuggestResult;
          console.log("familySuggestResult RETURN->", this.familySuggestResult);
          this.familySuggestData = this.familySuggestResult.result_list;
          //debugger;
          this.suggested_count = this.familySuggestData.length;
          console.log("***  this.suggested_count ==== ",this.suggested_count)
        }
    );
  }
  getSuggestedDetails(item){
    var stateParam = {
      itemData: item,
      getFamilySuggestList: this.getFamilySuggestList()
    };
    this.router.navigate(['suggestdetails'],{state: stateParam});
  }

  allSuggest(){

  }
  suggestNewTasks(){
    this.router.navigate(['tabs/suggest']);
  }
}
