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

@Component({
  selector: 'app-suggest',
  templateUrl: './suggest.page.html',
  styleUrls: ['./suggest.page.scss'],
})
export class SuggestPage implements OnInit {
    @ViewChild(IonModal) modal: IonModal;

  tabs = 'about';

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

  ngOnInit() {
    this.  getFamilySampleSuggest();
  }

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

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

  onEnroll() {
    this.router.navigate(['enroll']);
  }

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

  sampleSuggestTotalData:any;
  sampleSuggestData: [];
  getFamilySampleSuggest(){
    this.usrData =
        {
          action:22027,
          member_id: this.sessionDataProviderService.member_id,
          uid: this.sessionDataProviderService.member_uid,
          sessionid: this.sessionDataProviderService.session ,
          limit:20, page:1,offset: 0
        };

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

  }
modalSeleted:any;
    suggestDetails(item){
        this.modalSeleted =  item;
        this.modal.present();
    }

    sendSuggestedTask(){

        this.cancel();
    }


    message = 'This modal example uses triggers to automatically open a modal when the button is clicked.';
    name: string;

    cancel() {
        this.modal.dismiss(null, 'cancel');
    }

    confirm() {
        this.modal.dismiss(this.name, 'confirm');
    }

    onWillDismiss(event: Event) {
        const ev = event as CustomEvent<OverlayEventDetail<string>>;
        if (ev.detail.role === 'confirm') {
            this.message = `Hello, ${ev.detail.data}!`;
        }
    }

    // customCounterFormatter(inputLength: number, maxLength: number) {
    //     return `${maxLength - inputLength} characters remaining`;
    // }
}
