import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams ,ModalController, ViewController} from 'ionic-angular';
import {Validators, FormBuilder, FormGroup, FormControl } from '@angular/forms';
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer';
import { File } from '@ionic-native/file';
import { ImagePicker } from '@ionic-native/image-picker';
import { Storage } from '@ionic/storage';
import {Myservice} from '../../providers/myservice';

@IonicPage()

@Component({
  selector: 'page-addreview',
  templateUrl: 'addreview.html',
})

export class AddReview {

	rateval = {
		comments: '',
		rate: ''
	}
	user_data:any;
	garage_id:any;
	booking_id:any;
	
	constructor(public navCtrl: NavController, public navParams: NavParams,private transfer: FileTransfer, private file: File, private formBuilder: FormBuilder,private imagePicker: ImagePicker,public storage:Storage, private myservice: Myservice,public modalCtrl: ModalController, public viewCtrl:ViewController) {
		this.garage_id = this.navParams.get('garage_id');
		this.booking_id = this.navParams.get('booking_id');
		console.log(this.garage_id);
		this.storage.get('user_data').then((user_data) => {
				console.log(user_data);
			if(user_data){
				this.user_data= user_data;
			}
		})
	}

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

	back(){
		this.navCtrl.pop();
	}
	
	success(){
		this.navCtrl.push('SuccessPage');
	}	
	
	 
	
	onsubmit(vals){
	 
		console.log(this.rateval);
		var obj = {'rate' : this.rateval.rate,'comments' : this.rateval.comments,'user_id' : this.user_data.id,'garage_id' : this.garage_id,'booking_id' : this.booking_id }
		this.myservice.show_loader();
			this.myservice.load_post(obj ,'addRating').subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				this.myservice.show_alert("Success", data.message);
				this.viewCtrl.dismiss(data);
				 
			}
			else
				this.myservice.show_alert("Error", data.message);
		});
		
		
	}
	
	  

}
