import { Component, OnInit } from '@angular/core';
import { AlertController, NavController } from '@ionic/angular';
import Parse from 'parse';

Parse.initialize("dev");
Parse.serverURL = 'http://web2023.fmode.cn:9999/parse';

@Component({
  selector: 'app-page-mine',
  templateUrl: './page-mine.component.html',
  styleUrls: ['./page-mine.component.scss']
})
export class PageMineComponent implements OnInit {

  private _user1: Parse.User | undefined;

  constructor() {
    this.updateUserInfo();
  }

  get user1(): Parse.User | undefined {
    return this._user1;
  }

  updateUserInfo() {
    const currentUserString = localStorage.getItem('currentUser');
    console.log('Current user string:', currentUserString);
    if (currentUserString) {
      const currentUser = JSON.parse(currentUserString);
      console.log('Parsed current user:', currentUser);
      this._user1 = new Parse.User(currentUser);
      console.log('Updated user1:', this._user1);
    }
  }

  ngOnInit() {
  }

  async logout() {
    console.log('Logging out...');
    await Parse.User.logOut();
    console.log('User logged out');
    localStorage.removeItem('currentUser');
    console.log('Local storage removed');
    this.updateUserInfo();
  }
}
