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';

@Component({
  selector: 'app-relation',
  templateUrl: './relation.component.html',
  styleUrls: ['./relation.component.scss'],
  standalone: true,
  imports: [...ionicStandaloneModules, NavComponent],
})
export class RelationComponent implements OnInit {
  list: Array<any> = [];
  disbable: boolean = true;
  constructor(private aiServ: AiChatService) {}

  async ngOnInit() {
    this.list = await this.aiServ.getRelation(20,this.list.length);
    console.log(this.list);
  }
  async onIonInfinite(ev: any) {
    let result = await this.aiServ.getRelation(20,this.list.length);
    if (result.length == 0) {
      this.disbable = false;
    }
    this.list.push(...result)
    setTimeout(() => {
      (ev as InfiniteScrollCustomEvent).target.complete();
    }, 500);
  }
}
