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

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

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

    ngOnInit() {
      //  this.getWalletData();
      //  this.getPaymentHxData();
    }

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

    ionViewDidEnter(){
        this.getWalletData();
        this.getPaymentHxData();
    }

    addCredit(item){
      //  debugger;
        this.router.navigate(['addcredit'],{state: item});
    }
    onReceipt(item) {
        this.router.navigate(['receipt']);
    }
    walletResult:any;
    walletData: [];
    usrData: {
        action:11200, member_id: number, uid: string, sessionid: string, limit:20, page:1
    };
    getWalletData(){
        this.usrData = {action:11200, member_id: this.sessionDataProviderService.member_id, uid: this.sessionDataProviderService.member_uid, sessionid: this.sessionDataProviderService.session, limit:20, page:1 }
        this.wrenchService.getUserWallets(this.usrData).subscribe(
            walletResult => {
                this.walletResult = walletResult;
                console.log("BANNERS RETURN->", this.walletResult);
                this.walletData = this.walletResult.result_list;
                // debugger;
                console.log("BANNERS RETURN DATA->", this.walletData);
                //  this.blogDataService.setBlogData(this.blogResult.blog_data);
            }
        );

    }

    //
    paymentHxData:any;
    paymentData: [];
    getPaymentHxData(){
        this.usrData = {action:11200, member_id: this.sessionDataProviderService.member_id, uid: this.sessionDataProviderService.member_uid, sessionid: this.sessionDataProviderService.session , limit:20, page:1}
        this.wrenchService.getPaymentHx(this.usrData).subscribe(
            paymentHxData => {
                this.paymentHxData = paymentHxData;
                console.log("PAH HX RETURN->", this.paymentHxData);
                this.paymentData = this.paymentHxData.result_list;
                // debugger;
                console.log("BANNERS RETURN DATA->", this.paymentData);
                //  this.blogDataService.setBlogData(this.blogResult.blog_data);
            }
        );

    }

    startRedeem(item){
        this.router.navigate(['redeem'],{state: item} );
    }
}
/*
'limit' => int 20
  'page' => int 1
  'action' => int 15046
 */
