import { Component } from '@angular/core';
import { NavController,LoadingController,AlertController,App } from 'ionic-angular';
import { AuthServiceProvider} from '../../providers/auth-service/auth-service';
import { LoginPage } from '../login/login';

@Component({
  selector: 'page-about',
  templateUrl: 'about.html'
})
export class AboutPage {

  studentInformation  = [];
  id : any;
  loading :any;
  Logoutalert: any;
  commonUrl: any;
  constructor(public alertCtrl:AlertController , 
    public loadingCtrl:LoadingController,
    public navCtrl: NavController, 
    public authService:AuthServiceProvider,
    public app:App) {
    this.id = localStorage.getItem("ID");
    this.commonUrl = this.authService.commonUrl;
    let Requested = {requestedBy:this.id,requestedFrom:"2"}
            //console.log("req"+Requested);
      this.studentloading();
           
    this.authService.studentGetInfo(Requested).subscribe(getStudent=>{
      
      if(getStudent.studentStatus == true){
       
        localStorage.setItem('StudentDetails', getStudent.studentDetails); 
        this.studentInformation =  getStudent.studentDetails;
       this.loading.dismiss();
     
           
          
       }
     });
  }
    
  studentloading(){
    this.loading = this.loadingCtrl.create({
      content: "Please wait...",
    });
    this.loading.present();
 
  }
  logoutalert(){
    this.logout();
    this.Logoutalert = this.alertCtrl.create({
      title:'Successfully Logout',
      buttons:['Ok']
    });
  this.Logoutalert.present();
  }  
  
  logout(){
    
    
    window.localStorage.removeItem('ID');
    window.localStorage.removeItem('userMobile');
    window.localStorage.removeItem('password');
    //window.localStorage.removeItem('password');
    window.localStorage.removeItem('feesID');
    this.app.getRootNav().setRoot(LoginPage);
    this.navCtrl.popToRoot(); 
    
  }
}
