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


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

	booking_id:any;
	request_val:any;
	stat:any;
	user_data:any;
	book_list:any;
	from_push:any = false;
 
	
	constructor(public navCtrl: NavController, public navParams: NavParams,public storage:Storage, private myservice: Myservice,public events:Events) {
		this.booking_id = this.navParams.get('id');
		this.stat = this.navParams.get('stat');
		this.from_push = this.navParams.get('from_push');
		if(this.booking_id){
			this.getSingleBookings();
			this.update_read_status();

			this.storage.get('user_data').then((user_data) => {
				if(user_data){
					this.user_data=user_data
					console.log(this.user_data);
				 
				}
		})
		}
	}

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

	back(){
		this.navCtrl.pop();
	}

	repair(statuss){
		 
		this.myservice.show_loader();
		this.myservice.load_get('update_book_status/id/'+this.booking_id+'/status/'+statuss).subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				this.myservice.show_alert("Success",data.message);
				this.getSingleBookings();
				this.update_read_status();
				 
				this.events.publish('user:incomp_read_status','');
			}	
			else
				this.myservice.show_alert("Error",data.message)
		});
		 
	}	
	
	getSingleBookings(){
		this.myservice.show_loader();
		this.myservice.load_get('getSingleBookings/id/'+this.booking_id).subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				this.request_val = data.data;
			}
		});
	}
	
	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);
				 
			}
		});
	}
	
	update_read_status(){
		this.myservice.show_loader();
		this.myservice.load_get('update_bookread_status/id/'+this.booking_id+'/stat/'+this.stat).subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
			 
				this.events.publish('user:read_status','');
				this.events.publish('user:incomp_read_status','');
				console.log(data);
			}
		});
	}
	
	cancel_booking(){
	
	}

}
