import { Component,EnvironmentInjector,inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IonBadge, IonButton, IonButtons, IonContent, IonHeader, IonIcon, IonItem, IonList, IonMenu, IonMenuButton, IonTitle, IonToolbar } from '@ionic/angular/standalone';
import { IonLabel } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import {folderOutline,timeOutline,starOutline,heartOutline,chevronForwardOutline,personOutline,shieldOutline,callOutline,lockClosedOutline} from 'ionicons/icons';
addIcons({folderOutline,timeOutline,starOutline,heartOutline,chevronForwardOutline,personOutline,shieldOutline,callOutline,lockClosedOutline})

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 { Router } from '@angular/router';
import { ModalController } from '@ionic/angular/standalone';
import { AlertController } from '@ionic/angular/standalone'; // 导入所需的模块

@Component({
  selector: 'app-tab5',
  templateUrl: './tab5.component.html',
  styleUrls: ['./tab5.component.scss'],
  standalone: true,
  imports: [CommonModule,IonIcon,IonLabel,IonList,IonButton,IonMenu,IonToolbar,IonMenuButton,IonTitle,IonButtons,IonItem,IonHeader,IonContent,IonBadge
  ],
})
export class Tab5Component{

  public environmentInjector = inject(EnvironmentInjector);

 currentUser:CloudUser|undefined
   constructor(
    private alertController: AlertController,
     private router: Router,
     private modalCtrl:ModalController) {
     addIcons({ folderOutline,timeOutline,starOutline,heartOutline});
     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;
 }








 
 async showAlert() {
  const alert = await this.alertController.create({
    header: '提示', // 提示框的标题
    message: '请先登录以查看个人信息。', // 提示框的消息
    buttons: ['确定'], // 按钮文本，用户点击后关闭提示框
  });

  await alert.present(); // 显示提示框
}
}
