import { Component, OnInit } from '@angular/core';
import { InfiniteScrollCustomEvent } from '@ionic/core';
import { NavComponent } from '../../../app/components/nav/nav.component';
// import { AiChatService } from '../../../services/aichart.service';
import { ionicStandaloneModules } from '../../ionic-standalone.modules';
import * as Parse from 'parse';
import { CommonModule, DatePipe } from '@angular/common';
import { Router } from '@angular/router';
@Component({
  selector: 'app-records',
  templateUrl: './records.component.html',
  styleUrls: ['./records.component.scss'],
  standalone: true,
  imports: [...ionicStandaloneModules, NavComponent,CommonModule],
  providers: [DatePipe],
})
export class RecordsComponent implements OnInit {
  user:Parse.User = Parse.User.current();
  list: Array<any> = [];
  getType(s: string): {title:string,color:string} {
    let obj: any = {
      '100': {
        title:'申请中',
        color:'#ffca22',
      },
      '200':{
        title:'已提现',
        color:'#42d96b',
      },
      '300': {
        title:'驳回',
        color:'#cb1a27',
      },
    };
    return obj[s];
  }
  constructor(private router: Router) {}

  async ngOnInit() {
    this.getWithdraw()
  }

  async getWithdraw(){
    let query = new Parse.Query('UserAgentWithdraw');
    query.equalTo('user', this.user?.id);
    query.notEqualTo('isDeleted',true)
    query.descending('createdAt')
    query.limit(20)
    query.skip(this.list.length)
    let r = await query.find();
    this.list.push(...r)
    console.log(r);
    return r
  }
  async onIonInfinite(ev: any) {
    let result = await this.getWithdraw();
    if (result.length == 0) {
      (ev as InfiniteScrollCustomEvent).target.disabled = true;
    }
    setTimeout(() => {
      (ev as InfiniteScrollCustomEvent).target.complete();
    }, 500);

    
  }
  toUrl(id: string) {
    this.router.navigate(['account/records/detail/' + id]);
  }
}
