import { Component, OnInit } from '@angular/core';
import * as Parse from 'parse';
import { Router, ActivatedRoute } from '@angular/router';
import { NavComponent } from '../../../app/components/nav/nav.component';
import { ionicStandaloneModules } from '../../ionic-standalone.modules';
import { AiChatService } from '../../../services/aichart.service';

@Component({
  selector: 'app-wattle',
  templateUrl: './wattle.component.html',
  styleUrls: ['./wattle.component.scss'],
  standalone: true,
  imports: [...ionicStandaloneModules, NavComponent],
})
export class WattleComponent implements OnInit {
  company: any = localStorage.getItem('company');
  wallet:number = 0
  isAnthor:boolean = false
  anthorWallet:any
  constructor(
    private activatRoute: ActivatedRoute,
    private aiServ: AiChatService,
    private router: Router
  ) {}
  account: any = {};

  ngOnInit() {
    this.activatRoute.paramMap.subscribe(async(parms) => {
      this.getAccount();
    });
  }
  back() {
    this.router.navigate(['account/tabs/my']);
  }
  async getAccount() {
    let id = Parse.User.current()?.id;
    this.account = await this.aiServ.getWallet(id!)
    console.log(this.account);
    this.isAnthor = this.aiServ.identity
    // if(this.aiServ.identity){
      this.anthorWallet = await this.aiServ.getAuthorWallet(id!)
      console.log(this.anthorWallet);
    // }
  }

  // showBalance(balance:number) {
  //   if (balance) {
  //     return Number(balance.toFixed(2))
  //   } else {
  //     return 0
  //   }
  // }
  record() {
    this.router.navigate(['account/log']);
  }
  records() {
    this.router.navigate(['account/records']);
  }
  recharge() {
    this.router.navigate(['account/recharge']);
  }
  withdrawal() {
    this.router.navigate(['account/withdrawal']);
  }
  toBank() {
    this.router.navigate(['account/bankcard']);
  }
}
