import { Component } from '@angular/core';
import { NavController,MenuController,LoadingController,AlertController,App,ModalController } from 'ionic-angular';
import { AuthServiceProvider } from '../../providers/auth-service/auth-service';
import { LoginPage } from '../login/login';
import { installmentDetails } from '../installment-details/installmentDetails';
import { paidDetails } from '../paid-details/paidDetails';
@Component({
  selector: 'page-fees',
  templateUrl: 'feesDetails.html'
})
export class feesDetails {
  CourseDetails : string  = "Fees";
  company : any;
  loading : any;
  
  name:any;
  StudentName : any;
  coursedetails : any;
  Logoutalert : any;
  commonUrl : any;
  CourseID : any;
  Coursestatus = [];
  // tab2 = page2;

  //test:string;
  constructor(public alertCtrl: AlertController,
    public loadingCtrl:LoadingController, 
    public navCtrl: NavController,
    public Menu:MenuController,
    private authService:AuthServiceProvider,
    public app:App,
    public modalCtrl:ModalController) {
      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){
      this.CourseID =   window.localStorage.getItem("CourseID");
     
        //localStorage.setItem('StudentDetails', getStudent.courseStatus.); 
        this.coursedetails =  getStudent.courseDetails.courseStatus;
       for (let course of this.coursedetails){
         if(this.CourseID == course.CourseID){
          this.Coursestatus = course;
          //console.log(this.Coursestatus);
         }
       }
      //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('feesID');
    
    this.app.getRootNav().setRoot(LoginPage);
    this.navCtrl.popToRoot(); 
    
  }
  studentloading(){
    this.loading = this.loadingCtrl.create({
      content: "Please wait...",
    });
    this.loading.present();
 
  }
  installmentselection(feesID) {
    //console.log(feesID);
    localStorage.setItem('feesID', feesID); 
    let modal = this.modalCtrl.create(installmentDetails);
    modal.present();
      
    
      
 
}
paidselection(feesID) {
  //console.log(feesID);
  localStorage.setItem('feesID', feesID); 
  let modal = this.modalCtrl.create(paidDetails);
  modal.present();
    
  
    

}
  // toggleItem(i, j) {
  //   this.information[i].children[j].open = !this.information[i].children[j].open;
  // }
}
