import { Component, OnInit } from '@angular/core';
import { CloudUser } from 'src/lib/ncloud';
import { ModalUserEditComponent } from '../modal-user-edit/modal-user-edit.component';
import { ModalController } from "@ionic/angular/standalone";
import {
  IonContent, IonHeader, IonTitle, IonToolbar, IonCard,
  IonCardHeader, IonCardTitle, IonCardSubtitle, IonCardContent,
  IonButton, IonAvatar, IonList, IonItem, IonLabel, IonNote, IonIcon
} from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import {
  personOutline, calendarOutline, createOutline,
  logOutOutline, logInOutline, personCircleOutline
} from 'ionicons/icons';

@Component({
  selector: 'app-page-mine',
  templateUrl: './page-mine.component.html',
  styleUrls: ['./page-mine.component.scss'],
  standalone: true,
  imports: [
    IonContent, IonHeader, IonTitle, IonToolbar, IonCard,
    IonCardHeader, IonCardTitle, IonCardSubtitle, IonCardContent,
    IonButton, IonAvatar, IonList, IonItem, IonLabel, IonNote, IonIcon
  ]
})
export class PageMineComponent implements OnInit {
  currentUser: CloudUser | undefined;

  constructor(private modalCtrl: ModalController) {
    this.currentUser = new CloudUser();
    addIcons({
      personOutline, calendarOutline, createOutline,
      logOutOutline, logInOutline, personCircleOutline
    });
  }

  async edit() {
    const modal = await this.modalCtrl.create({
      component: ModalUserEditComponent,
    });
    modal.present();

    const { data, role } = await modal.onWillDismiss();
  }

  async login() {
    let user: any = new CloudUser();
    user = await user?.login("abctest", "1234");
    if (user?.id) {
      this.currentUser = user;
    }
  }

  logout() {
    this.currentUser?.logout();
    this.currentUser = undefined;
  }

  ngOnInit() { }
}