import { Component, NgModule, OnInit } from '@angular/core';
import { ModalController, IonModal, IonHeader, IonToolbar, IonTitle, IonContent, IonList, IonItem, IonLabel, IonAvatar, IonButton, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView, IonCardContent, IonCardTitle, IonCardHeader, IonCard, IonIcon, IonButtons, IonInput, IonRefresherContent, IonRefresher } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { airplane, bluetooth, call, wifi } from 'ionicons/icons';
import { CommonModule } from '@angular/common';
import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
// import { FmMarkdownPreview } from 'fmode-ng';
import { Router } from '@angular/router';
addIcons({ airplane, bluetooth, call, wifi });
@Component({
  selector: 'page-my-health',
  templateUrl: './page-my-health.component.html',
  styleUrls: ['./page-my-health.component.scss'],
  standalone: true,
    imports: [
      IonHeader, IonToolbar, IonTitle, IonContent,
      IonLabel,IonItem,IonList,IonAvatar,CommonModule,IonButton,
      IonSegment, IonSegmentButton,
      IonSegmentContent,IonSegmentView,IonCardContent, IonCardTitle, IonCardHeader,IonCard,
      IonModal,IonIcon, IonButtons,IonInput,IonRefresher,IonRefresherContent
      // FmMarkdownPreview,
    ]
})
export class PageMyHealthComponent  implements OnInit {
  handleRefresh(event:any) {
    setTimeout(() => {
      // Any calls to load data go here
      this.loadData();
      event.target.complete();
    }, 2000);
  }

  avatar : string = "../assets/imgs/avatar.png";
  currentUser : CloudUser | undefined ;
  objectId : string = "";

  constructor(
    private router: Router
  ) {
    this.currentUser = new CloudUser();
    this.avatar = this.currentUser.data["avatar"];
    this.objectId = this.currentUser.data['objectId'];
  }
  allMessage : Array<CloudObject> = [];

  async loadData(){
    console.log("objectId",this.objectId);
    let query = new CloudQuery('Consultation');
    console.log(query.include("user"))
    // 根据用户id查询， 其中用户id字段是指针，指向User表中的objectId
    // query.equalTo("user",{ "__type": "Pointer", "className": "_User", "objectId": this.objectId });
    this.allMessage = await query.find();
    console.log("allMessage",this.allMessage);
  }
   
  ngOnInit() {
    this.loadData();
  }
  back:string = "back"
  backHome(){
    this.router.navigate(['/tabs/tab1']);
  }
  gotouser(){

  }
}
