import { Component } from '@angular/core';
import { IonHeader, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent, IonButton, IonCardHeader, IonCardTitle, IonCardSubtitle, ModalController, IonRefresher, IonRefresherContent, IonLabel, IonItem, IonIcon, IonList, IonAvatar } from '@ionic/angular/standalone';
import { CloudUser } from 'src/lib/ncloud';
import { openUserEditModal } from 'src/lib/user/modal-user-edit/modal-user-edit.component';
import { openUserLoginModal } from 'src/lib/user/modal-user-login/modal-user-login.component';
import { EditTagComponent } from '../component/edit-tag/edit-tag.component';
import { Router } from '@angular/router';
@Component({
  selector: 'app-tab4',
  templateUrl: 'tab4.page.html',
  styleUrls: ['tab4.page.scss'],
  standalone: true,
  imports: [IonHeader, 
    IonToolbar, 
    IonTitle,
     IonContent, 
     IonLabel,
     IonItem,
     IonIcon,
     IonList,
     IonAvatar,
    IonCard,
    IonCardContent,
    IonButton,
    IonCardHeader,
    IonCardTitle,
    IonCardSubtitle,
    EditTagComponent,
    IonRefresher,
    IonRefresherContent
  ],
})
export class Tab4Page {
  //主题页面切换
  pageNum:Number=0
  changeNum1(){
    this.pageNum=1;
  }
  changeNum2(){
    this.pageNum=2;
  }

  //页面刷新
  handleRefresh(event:any) {
    setTimeout(() => {
      // Any calls to load data go here
      this.currentUser = new CloudUser();
      event.target.complete();
    }, 2000);
  }

  // goToCollection(){
  //   console.log("goToCollection");
  // }

  //前往头像生成页面
  goToAvatar(){
    console.log(['route'])
    this.router.navigate(['/tabs/picture'])
  }

  //前往健康信息显示页面
  goToHealth(){
    this.router.navigate(['/tabs/my-health'])
  }

  //前往帮助页面
  goToHelp(){
    
    this.router.navigate(['/tabs/help'])
  }

  //前往密码修改页面
  goToKey(){
    
    this.router.navigate(['/tabs/password'])
  }

  //前往指南页面
  goToGuide(){
    this.router.navigate(['/tabs/guide'])
  }

  //前往天气时间页面
  goToWeatherTime(){
    this.router.navigate(['/tabs/weather-time'])
  }

  //前往本地图片上传
  goToLocalAvatar(){
    this.router.navigate(['comp-uploader-hwobs'])
  }

  //用户
  currentUser:CloudUser|undefined
  constructor(
    private router: Router,
    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();
    this.pageNum=0;
  }

  //用户信息编辑
  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;
}
}
