import { Component } from '@angular/core';
import { IonHeader, IonToolbar, IonTitle, IonContent, IonButton } from '@ionic/angular/standalone';
import { ExploreContainerComponent } from '../explore-container/explore-container.component';
import { IonCard, IonCardContent, IonCardHeader, IonCardTitle, IonIcon, IonItem, IonLabel, IonList } from '@ionic/angular/standalone';
import { IonButtons } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { calendarOutline, chatbubbleEllipsesOutline, chatbubbleOutline, documentTextOutline, personOutline, settingsOutline } from 'ionicons/icons';
import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
import { ModalController } from '@ionic/angular/standalone';
import { openUserLoginModal } from 'src/lib/user/modal-user-login/modal-user-login.component';
import { openUserEditModal } from 'src/lib/user/modal-user-edit/modal-user-edit.component';
import { IonMenu, IonMenuButton } from '@ionic/angular/standalone';
import { IonThumbnail } from '@ionic/angular/standalone';
import { CommonModule } from '@angular/common';
import { IonModal } from '@ionic/angular/standalone';
import { IonAlert } from '@ionic/angular/standalone';

addIcons({ settingsOutline, chatbubbleEllipsesOutline, documentTextOutline, calendarOutline, chatbubbleOutline, personOutline}) 

@Component({
  selector: 'app-tab3',
  templateUrl: 'tab3.page.html',
  styleUrls: ['tab3.page.scss'],
  standalone: true,
  imports: [IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent,
    IonButtons, IonIcon, IonCard, IonCardHeader, IonCardTitle, IonCardContent, IonList, IonItem, IonLabel,IonButton,
    IonMenu, IonMenuButton,
    IonThumbnail, CommonModule,
    IonModal, IonAlert
  ],
})
export class Tab3Page {

  alertButtons = ['Action'];

  currentUser:CloudUser|undefined
  constructor(private modalCtrl:ModalController) {
    this.currentUser = new CloudUser();
  }
  async login(){
    // 弹出登录窗口
    let user = await openUserLoginModal(this.modalCtrl);
    if(user?.id){
      this.currentUser = user
    }
  }
  async signup(){
    // 弹出注册窗口
    let user = await openUserLoginModal(this.modalCtrl,"signup");
    if(user?.id){
      this.currentUser = user
    }
  }
  logout(){
    this.currentUser?.logout();
  }

  editUser(){
    openUserEditModal(this.modalCtrl)
  }

  editTags:Array<String>=[]
   async setTagsValue(ev:any){
    let currentUser = new CloudUser();
    let userPrompt = ``
    if(!currentUser?.id){
      console.log("用户未登录，请登录后重试");
      let user = await openUserLoginModal(this.modalCtrl);
      if(!user?.id){
        return
      }
      currentUser = user;
    }
  //console.log("setTagsValue",ev);
  this.editTags=ev;
}

  ngOnInit() {
    // 生命周期：页面加载后，运行专家列表加载函数
    this.loadExpertList()
  }

  // 创建用于数据列表存储的属性
  expertList:Array<CloudObject> = []
  // 查询并加载医生列表的函数
  async loadExpertList(){
    let query = new CloudQuery("Expect");
    this.expertList = await query.find()
    console.log(this.expertList)
  }

}
