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) {
    let id = this.navParams.get("id");
    this.slidertab = id;
    console.log("id", id);
    setTimeout(() => {
    this.goToSlide(id);
    }, 500)
    this.slidertab = 1;
	
	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,stat){
      this.navCtrl.push('BookingDetail',{'id' :id,'stat' :stat });
    }
	
	  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);
				 
			}
		});
  }
    

}
