import { Component, OnInit } from '@angular/core';
import {
  IonSearchbar,
  IonToolbar,
  IonTitle,
  IonHeader,
  IonContent,
  IonCard,
  IonCardHeader,
  IonCardTitle,
  IonList,
  IonCardContent,
  IonItem,
  IonLabel,
  IonButton,
  IonIcon,
  IonInput,
  IonCardSubtitle,IonButtons
} from '@ionic/angular/standalone';
import { CommonModule } from '@angular/common';
import { 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 { Router } from '@angular/router';
@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss'],
  standalone: true,
  imports: [
    IonList,
    IonCard,
    IonContent,
    IonHeader,
    IonSearchbar,
    IonToolbar,
    IonTitle,
    IonCard,
    IonCardHeader,
    IonCardTitle,
    IonCardContent,
    IonItem,
    IonLabel,
    IonButton,
    IonIcon,
    IonInput,
    CommonModule,
    IonCardSubtitle,
    IonButtons,
  ],
})
export class LoginComponent implements OnInit {
  
  currentUser: CloudUser | undefined;
  //定义字段
  username: string = '';
  password: string = '';
  email: string = '';
  phone: string = '';
  realName: string = '';
  age: number = 0; // 使用 number 类型来表示年龄
  gender: '男' | '女' | '其他' = '其他'; // 限制性别字段的值为“男”、“女”或“其他”


  constructor(private modalCtrl:ModalController,private router:Router) {
    this.currentUser = new CloudUser();
  }
  async login() {
    //弹出登录窗口
    let user = await openUserLoginModal(this.modalCtrl);
    if(user?.id){
      this.currentUser = user
    }
  }


  logout() {
    this.currentUser?.logout();
  }
  async signup(){
    //弹出注册窗口
    let user = await openUserLoginModal(this.modalCtrl,"signup");
    if(user?.id){
      this.currentUser = user
    }
  }
  // 添加返回到 Tab 4 的方法
  goToTab4() {
    this.router.navigate(['/tabs/tab4']); // 假设你的 tab4 路由是这个路径
  }
  editUser(){
    openUserEditModal(this.modalCtrl)
  }
  ngOnInit() {}
}
