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

/**
 * Generated class for the OverviewPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-overview',
  templateUrl: 'overview.html',
})
export class OverviewPage {
garage_name:any;
garage_id:any;
bookvals:any;
page:any;
  constructor(public navCtrl: NavController, public navParams: NavParams, public storage: Storage, private myservice: Myservice) {
	this.garage_name = this.navParams.get('garage_name')
	this.garage_id = this.navParams.get('garage_id')
	this.bookvals = this.navParams.get('bookvals')
	this.page = this.navParams.get('page')
	console.log('this.garage_name' ,this.garage_name)
	console.log('this.bookvals' ,this.page)
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad OverviewPage');
  }
  
  book(){
	 // this.myservice.show_loader();
	 var service_name =this.bookvals.description
	 if(this.page ='quotes')
		 service_name  = this.bookvals.service_name
		 
	var obj = { 'book_date' : this.bookvals.book_date ,  'book_time' : this.bookvals.book_time ,'service_name' : service_name, 'discount' : this.bookvals.discount, 'garage_id' : this.garage_id,  'price' : this.bookvals.price, 'service' : this.bookvals.service, 'total_price' : this.bookvals.total_price,'user_id' :this.bookvals.user_id,'offer_id' :this.bookvals.id}
			this.myservice.load_post(obj,'book_garage').subscribe(data => {
			//this.myservice.hide_loader();
			if(data.status == 'success'){
				//alert("hi");
				
				//this.myservice.show_alert('Success',data.message);
				var datas = {'garage_name':this.garage_name,'bookvals' :this.bookvals}
				// this.events.publish('user:notifications', '');
				 this.navCtrl.push('SuccessPage',{'datas':datas,'page' : this.page });	
				 
			}else if(data.status == 'booked'){
				this.myservice.show_alert('Error',data.message);
				this.navCtrl.push('TabsPage');	
			}
			else
				this.myservice.show_alert('Error',data.message);
		});
  }

}
