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


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

	pool_id:any;
	request_val:any;
	from_push:any = false;
	
	constructor(public navCtrl: NavController, public navParams: NavParams,public storage:Storage, private myservice: Myservice,public events:Events,private photoViewer: PhotoViewer) {
		this.pool_id = this.navParams.get('pool_id');
		this.from_push = this.navParams.get('from_push');
		if(this.pool_id){
			this.getSingleQuote();
			this.update_read_status();
		}
	}

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

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

	quote(){
		this.navCtrl.push('QuotePage',{'pool_id' :this.pool_id});
	}
	
	getSingleQuote(){
		this.myservice.show_loader();
		this.myservice.load_get('getSingleQuote/id/'+this.pool_id).subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				this.request_val = data.result;
			}
		});
	}
	
	view_img(url){
		this.photoViewer.show(url);
	}
	
	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:read_stat', '');
				//this.events.publish('user:notifications', this.user_data.id);
				console.log(data);
			}
		});
	}

}
