import { Component, OnInit } from '@angular/core';
import { Router, NavigationExtras } from '@angular/router'
import { MermsServiceProviderService } from './../providers/merms-service-provider.service';
import { MermsSessionService } from './../merms-session.service';


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

  currentDateFormated: string = '10/10/2020';
  welcomeName: string = '';

  dashData: any;

  constructor(
    private router: Router,
    private mermsServiceProviderService: MermsServiceProviderService,
    private mermsSessionService: MermsSessionService
  ) {
    this.welcomeName = this.mermsSessionService.getUserFormatedName();
    this.currentDateFormated = this.mermsSessionService.getThisData();
  }

  ngOnInit() {
    this.getDashData();
  }

  currentProviderData: {
    sessionid: string,
    member_id: number,
    card_count: number
    card_type: number
  };

  cardData: any;
  pendingEncounterData: any;

  getDashData() {
    console.log('MermsServiceProviderService::getDashData() ########  @@@@  ########');
    this.currentProviderData = {
      sessionid: this.mermsSessionService.session,
      member_id: this.mermsSessionService.member_id,
      card_count: 100,
      card_type: 22000
    };

    try {
      this.mermsServiceProviderService.genericGetService('provider/recentencounter', this.currentProviderData).subscribe(cardData => {
        console.log("card data result 22k: ", cardData[0]['payload']);
        this.cardData = cardData[0]['payload'];
        if (cardData.hasOwnProperty('payload') && Array.isArray(cardData['payload'])) {
          this.cardData = cardData['payload'];
          console.log("card data result 22k: ", this.cardData);
        }
      });
    } catch (e) {
      console.log(e);
    }

    try {
      this.mermsServiceProviderService.genericGetService('provider/pendingencounter', this.currentProviderData).subscribe(pendingEncounterData => {
        console.log("card data result 22k: ", pendingEncounterData[0]['payload']);
        this.pendingEncounterData = pendingEncounterData[0]['payload'];

      });
    } catch (e) {
      console.log(e);
    }

    //


  }

  goSettings() {
    this.router.navigateByUrl('/merms-settings');
  }

goPracticepatients(){
  this.router.navigateByUrl('/merms-mypatients');
}

  goPatient(selPatData: any) {
    // Set our navigation extras object
    // that passes on our global query params and fragment
    console.log(selPatData);
    let navigationExtras2: NavigationExtras = {
      queryParams: selPatData,
      state: [0]
    };

    let navigationExtras: NavigationExtras = {
      queryParams: {
        special: JSON.stringify(selPatData)
      }
    };

    this.router.navigateByUrl('/merms-patient', navigationExtras);
  }
  goHome() {

  }
  goCalendar() {
    this.router.navigateByUrl('/merms-calendar');
  }
  goWallet() {
    this.router.navigateByUrl('/merms-wallet');
  }

  goOpenCare() {
    this.router.navigateByUrl('/merms-opencare');
  }
  goSelectPatient(patientData: any) {
    let navigationExtras: NavigationExtras = {
      queryParams: {
        special: JSON.stringify(patientData)
      }
    };
    this.router.navigateByUrl('/merms-selectedpatient',navigationExtras);
  }

}
