import { Component } from '@angular/core';
// import { Component } from '@angular/core';
import { Router } from '@angular/router';
// import { AuthService } from '../../services/auth.service';
import { NavController } from '@ionic/angular';
import { AlertController } from '@ionic/angular';

@Component({
  selector: 'app-tab3',
  templateUrl: 'tab3.page.html',
  styleUrls: ['tab3.page.scss']
})
export class Tab3Page {
  user = {
    username: '张三',
    avatarUrl: 'assets/美津未.jpg',
    campus: '东校区',
    building: '教学楼A',
    gender: '男'
  };

  editedUser = { ...this.user }; // Clone of user for editing

  editing = false;

  constructor(
    private router: Router,
    private alertController: AlertController
  ) {}

  onFileSelected(event: any) {
    const file: File = event.target.files[0];
    const reader = new FileReader();
    reader.onload = () => {
      this.editedUser.avatarUrl = reader.result as string;
    };
    reader.readAsDataURL(file);
  }

  startEditing() {
    this.editing = true;
  }

  saveChanges() {
    // Save changes to user object and exit editing mode
    this.user = { ...this.editedUser };
    this.editing = false;
    // Optionally, you can add logic here to save changes to backend
  }

  cancelEditing() {
    // Exit editing mode without saving changes
    this.editedUser = { ...this.user }; // Reset editedUser to original user
    this.editing = false;
  }

  logout() {
    // Handle logout logic here
  }
}
