import { Component } from '@angular/core';
import { IonHeader, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent, IonButton, IonCardHeader, IonCardTitle, IonCardSubtitle, ModalController } 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';

@Component({
  selector: 'app-tab4',
  templateUrl: 'tab4.page.html',
  styleUrls: ['tab4.page.scss'],
  standalone: true,
  imports: [IonHeader, IonToolbar, IonTitle, IonContent, 
    IonCard,IonCardContent,IonButton,IonCardHeader,IonCardTitle,IonCardSubtitle,
    EditTagComponent
  ],
})
export class Tab4Page {
  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;
}
}
