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


@Component({
  selector: 'page-paid',
  templateUrl: 'paidDetails.html'
})
export class paidDetails {
  CourseDetails : string  = "Fees";
  company : any;
  loading : any;
  
  name:any;
  StudentName : any;
  coursedetails : any;
  Logoutalert : any;
  commonUrl : any;
  feesID : 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 viewCtrl:ViewController) {
      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.feesID =   window.localStorage.getItem("feesID");
     
        //localStorage.setItem('StudentDetails', getStudent.courseStatus.); 
        this.coursedetails =  getStudent.courseDetails.courseStatus;
       for (let course of this.coursedetails){
         //console.log(course);
         for(let fees of course.feesDetails){
           //console.log("if"+this.feesID);
         if(this.feesID == fees.FeesID){
           //console.log(fees);
          this.Coursestatus = fees;
        }
         
         }
       }
      //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');
    
    this.app.getRootNav().setRoot(LoginPage);
    this.navCtrl.popToRoot(); 
    
  }
  studentloading(){
    this.loading = this.loadingCtrl.create({
      content: "Please wait...",
    });
    this.loading.present();
 
  }
  toggleSection(feesID) {
     //console.log(feesID);
      for(let paidDetails of feesID.paidDetails){
       // paidDetails.open = !paidDetails.open;
       console.log(paidDetails.BillDate);
      }
    
      
 
}
 closeModal(){
   this.viewCtrl.dismiss();
 }
  // toggleItem(i, j) {
  //   this.information[i].children[j].open = !this.information[i].children[j].open;
  // }
}
