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

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


  tabs = 'about';
suggestTotalData:any;
    suggestData:any;
suggestActionData:any;
  constructor(
      private navctr: NavController,
      private router: Router,
      public sessionDataProviderService: SessionDataProviderService,
      private alertController:AlertController,
      private wrenchService: WrenchService
  ) {
     // debugger;
    this.suggestTotalData  =  this.router.getCurrentNavigation().extras.state;
    this.suggestData =  this.suggestTotalData.itemData;


  //  console.log("XXXXX 1",   this.router.getCurrentNavigation().extras);
  //  console.log("XXXXX 2",   this.router.getCurrentNavigation().extras.state);
  }

  ngOnInit() {
  }

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

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

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



    async sendReminder(){

            const alert = await this.alertController.create({
                header: "Remind",
                message: "Confirm you are ready to send reminder ?",
                buttons: [
                    {
                        text: "Cancel",
                        role: "cancel",
                        handler: () => {
                            // this.getMyOffersData();
                        },
                    },
                    {
                        text: "Send",
                        handler: () => {
                            this.setSuggestStatus(222); // remind
                            this.onBack();
                        },
                    },
                ],
            });
            await alert.present();

    }
    async cancelSuggest(){
        const alert = await this.alertController.create({
            header: "Cancel",
            message: "Confirm you are ready to cancel item.",
            buttons: [
                {
                    text: "Cancel",
                    role: "cancel",
                    handler: () => {
                        // this.getMyOffersData();
                    },
                },
                {
                    text: "Delete",
                    handler: () => {
                        this.setSuggestStatus(555); // cancel
                        this.refreshTaskList();
                        this.onBack();
                    },
                },
            ],
        });
        await alert.present();
    }
  statusResult:any;
    //define('WRENCHBOARD_FAMILY_SGGESTSTATUS',   22026);

    suggestEditData: {
        action:number, member_id: number, uid: string, sessionid: string, suggest_uid:20, suggest_action: string,offset: 0
    };

  setSuggestStatus(suggest_action){
    this.suggestEditData =
        {
        action:22026,
        member_id: this.sessionDataProviderService.member_id,
        uid: this.sessionDataProviderService.member_uid,
        sessionid: this.sessionDataProviderService.session ,
        suggest_uid: this.suggestData.uid,
        suggest_action:suggest_action,offset: 0
        };

    this.wrenchService.setSuggestStatus(this.suggestEditData).subscribe(
        statusResult => {
          this.statusResult = statusResult;
          console.log("statusResult  RETURN->", this.statusResult);

          //this.total_family = this.familyData.length;
        }
    );

  }

}
