import { Component,ViewChild } from '@angular/core';
import { IonicPage, NavController, NavParams,Content,Slides, Events } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import {Myservice} from '../../providers/myservice';


@IonicPage()
@Component({
  selector: 'page-booking',
  templateUrl: 'booking.html',
})
export class Booking {

  currentIndex:any;
  slidertab:any;
  user_data:any;
  book_list:any;

  @ViewChild(Content) content: Content;
  @ViewChild('mySlider') slider: Slides;

  constructor(public navCtrl: NavController, public navParams: NavParams,public storage:Storage, private myservice: Myservice,public events:Events) {
	  
	setInterval(() => {
				 this.get_booking_back();
				 
	}, 10000);
    let id = this.navParams.get("id");
    this.slidertab = id;
    console.log("id", id);
    setTimeout(() => {
    this.goToSlide(id);
    }, 500)
    this.slidertab = 0;
	
	this.storage.get('user_data').then((user_data) => {
				if(user_data){
					this.user_data=user_data
					console.log(this.user_data);
					 this.get_booking();
				}
		})
		
		events.subscribe('user:read_status', userdetails => {
					console.log("read");
						this.get_booking();
					});
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ListVehiclePage');
  }

  goToSlide(id) {
    this.slider.slideTo(id, 500);
    }
    
    slideChanged() {
    let currentIndex = this.slider.getActiveIndex();
    this.slidertab = currentIndex;
    console.log("Current index is", currentIndex);
    }

    booking_details(id){
      this.navCtrl.push('BookingDetail',{'id' :id });
    }
	
	  get_booking(){
  
  	this.myservice.show_loader();
		this.myservice.load_get('getBookings/id/'+this.user_data.id).subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				this.book_list = data.data;
				console.log(this.book_list);
				 
			}
		});
  }
  	  get_booking_back(){
  
   
		this.myservice.load_get('getBookings/id/'+this.user_data.id).subscribe(data => {
		 
			if(data.status == 'success'){
				this.book_list = data.data;
				console.log(this.book_list);
				 
			}
		});
  }
    

}
