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

@IonicPage()
@Component({
  selector: 'page-shopdetail',
  templateUrl: 'shopdetail.html',
})
export class ShopdetailPage {
	user_data:any;
	profile:any;
	garage_id:any;
	page:any;
	offers:any;
	selected_services:any;
	services_pg:any;
	quote_val:any;
  constructor(public navCtrl: NavController, public navParams: NavParams, public storage: Storage, private myservice: Myservice,public modalCtrl: ModalController,public popoverCtrl: PopoverController) {
		this.garage_id = this.navParams.get('garage_id');
		console.log(this.garage_id);
		if(this.navParams.get('offers')){
			this.offers = this.navParams.get('offers');
			this.offers = this.offers.offers; 
		}
		if(this.navParams.get('services')){
			this.services_pg = this.navParams.get('services');
			console.log(this.services_pg)
		}
		console.log("offers", this.offers);		
		this.page = this.navParams.get('page');
		if(this.page == 'quotes')
			this.quote_val = this.navParams.get('quote_val'); 	
		console.log('page' , this.page)
		console.log('page' , this.quote_val)
		 
			this.storage.get('user_data').then((user_data) => {
				if(user_data){
					this.user_data=user_data
					
					console.log(this.user_data);
				}
		})
		this.get_profile(); 
		this.get_selected_services(); 
  }

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

  back()
  {
    this.navCtrl.pop();
  }
  		get_profile(){
		this.myservice.show_loader();
		this.myservice.load_get('getshopDetails/id/'+this.garage_id).subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				this.profile = data.result;
				console.log(this.profile)
			}
		});
	}
	get_selected_services(){
		this.myservice.show_loader();
		this.myservice.load_get('get_selected_services/id/'+this.garage_id).subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				this.selected_services = data.result;
				 
			}
		});
	}
	open_map(lat,lng){
		var obj ={'lat' : lat, 'lng' :lng}
		let modal = this.modalCtrl.create('MapPage',{'locations':obj});
		modal.onDidDismiss(data => {
			if(data) {
				
			}
		});
		modal.present();
 
	}
	
	presentPopover(myEvent) {
		let modal = this.modalCtrl.create('AddReview',{'garage_id':this.garage_id});
		modal.onDidDismiss(data => {
			if(data) {
				this.get_profile(); 
			}
		});
		modal.present({
			ev: myEvent
		});
	}
	
	book_now(){
		if(this.page == 'offers')
			var offers = this.navParams.get('offers'); 
			console.log(this.profile.timing);
			if(this.page == 'fixprice'){
				this.navCtrl.push('OfferedFixprices',{'page':this.page,'timing':this.profile.timing,'garage_name':this.profile.name,'garage_id':this.garage_id,'services' : this.services_pg });
			}else{
				
		
		/* let modal = this.modalCtrl.create('OfferedPage',{'page':this.page, 'offers' :offers,'timing':this.profile.timing,'garage_name':this.profile.name,'garage_id':this.garage_id });
		modal.onDidDismiss(data => {
			if(data) {
				 console.log(data);
				 this.navCtrl.push('SuccessPage',{'datas':data.datas,'page' : 'offered' });	
			}
		});
		modal.present(); */
		this.navCtrl.push('OfferedPage',{'page':this.page,'quote_val' : this.quote_val, 'offers' :offers,'timing':this.profile.timing,'garage_name':this.profile.name,'garage_id':this.garage_id,'services' : this.services_pg });
	}
	}

}
