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

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  @ViewChild(Slides) slides: Slides;
  company : any;
  loading : any;
  name:any;
  StudentName : any;
  studentInformation = [];
  Logoutalert : any;
  commonUrl : any;
  announcement : any;
  // tab2 = page2;

  //test:string;
  constructor(public alertCtrl: AlertController,
    public loadingCtrl:LoadingController, 
    public navCtrl: NavController,
    public Menu:MenuController,
    private authService:AuthServiceProvider,
    public app:App) {
      
            this.authService.getAnnouncement().subscribe(announcement=>{
              if(announcement.AnnouncementStatus == true){
             this.announcement =  announcement.details;
            }
            });
      this.commonUrl = this.authService.commonUrl;
      //console.log("home "+this.commonUrl);
    this.name = localStorage.getItem("ID");
    let Requested = {requestedBy:this.name,requestedFrom:"2"}
            //console.log("req"+Requested);

            this.studentloading();
    this.authService.studentGetInfo(Requested).subscribe(getStudent=>{
      
      if(getStudent.studentStatus == true){
       
        localStorage.setItem('StudentDetails', getStudent); 
        this.studentInformation =  getStudent.studentDetails;
       
      //console.log(this.studentInformation);
           this.loading.dismiss();
          
       }
     });
  }
 
  logoutalert(){
    
    let alert = this.alertCtrl.create({
      title:'Successfully Logout',
      buttons:['Ok']
    });
  alert.present();
  this.logout();
  }  
  ionViewDidEnter(){
    this.Menu.enable(false);
  }
  ionViewWillLeave(){
    this.Menu.enable(true);
  }
  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(); 
    
  }
  studentloading(){
    this.loading = this.loadingCtrl.create({
      content: "Please wait...",
    });
    this.loading.present();
 
  }
}
