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

@Component({
  selector: 'app-addcredit',
  templateUrl: './addcredit.page.html',
  styleUrls: ['./addcredit.page.scss'],
})
export class AddcreditPage implements OnInit {
    walletData:any;
    tabs = 'bank_redeem';
    curr_balance:number =0;
    currency_description : string='';
    currency_code:string='';
    wallet_uid:string='';
    isDisabled:boolean=false;
    curr_page:string= 'redeem_start';

  constructor(private navctr: NavController,
              private router: Router,
              public sessionDataProviderService: SessionDataProviderService,
              private wrenchService: WrenchService,
              public blogDataService: BlogDataService,
              public userWalletService: UserWalletService) {
      this.walletData  =  this.router.getCurrentNavigation().extras.state;
      if ( this.walletData != undefined ){
          this.curr_balance = this.walletData.amount*0.01;
          this.currency_code = this.walletData.code;
          this.currency_description = this.walletData.description;
          this.wallet_uid= this.walletData.wallet_uid;
      }
      else{
          this.onBack();
      }

  }

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

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

  usersCardsTotalData:any;
  usersCardsData: [];
  getUsersCardsList(){
    this.usrData =
        {
          action:11055,
          member_id: this.sessionDataProviderService.member_id,
          uid: this.sessionDataProviderService.member_uid,
          sessionid: this.sessionDataProviderService.session ,
          limit:20, page:1,offset: 0
        };

    this.wrenchService.getusersCardList(this.usrData).subscribe(
        usersCardsTotalData => {
          this.usersCardsTotalData = usersCardsTotalData;
          console.log("usersCardsTotalData TOTAL  RETURN->", this.usersCardsTotalData);
          this.usersCardsData = this.usersCardsTotalData.result_list;
          // debugger;
          console.log("usersCardsData RETURN DATA->", this.usersCardsData);
          //this.total_family = this.familyData.length;
        }
    );

  }
}
