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


@IonicPage()
@Component({
  selector: 'page-quote-details',
  templateUrl: 'quote-details.html',
})
export class QuoteDetailsPage {
	
	pool_id:any;
	quote_list:any;
	user_data:any;
	notify:any;
	from_push:any = false;

	constructor(public navCtrl: NavController, public navParams: NavParams,public storage:Storage, private myservice: Myservice,public events:Events) {
		this.pool_id = this.navParams.get('pool_id');
		this.from_push = this.navParams.get('from_push');
		if(this.pool_id){
			this.get_quote_details();
			this.update_read_status();
		}
		
		this.storage.get('user_data').then((user_data) => {
				console.log(user_data);
				if(user_data){
					this.user_data= user_data;
					
				}
		})
	}

	ionViewDidLoad() {
		console.log('ionViewDidLoad QuoteDetailsPage');
	}
	
	get_quote_details(){
		this.myservice.show_loader();
		this.myservice.load_get('get_quote_details/id/'+this.pool_id).subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				this.quote_list = data.result;
				console.log(this.quote_list);
			}
		});
	}	
	update_read_status(){
		this.myservice.show_loader();
		this.myservice.load_get('update_read_status/id/'+this.pool_id).subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				this.events.publish('user:notifications', '');
				//this.events.publish('user:notifications', this.user_data.id);
				console.log(data);
			}
		});
	}
	
	garage_details(id,pool_id,service_id,service_name,price){
		var obj = {'pool_id' : pool_id,'service_id' : service_id,'service_name' : service_name,'price' : price, 'user_accepted_status' :1,'garage_id':id,'quote_status':1}
		this.navCtrl.push('ShopdetailPage',{'garage_id' : id,'page' : 'quotes','quote_val' : obj});
	}

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

}
