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 HomePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
})
export class HomePage {
	user_data:any;
	offers:any;
  constructor(public navCtrl: NavController, public navParams: NavParams, public storage: Storage, private myservice: Myservice) {
		this.storage.get('user_data').then((user_data) => {
				console.log(user_data);
				if(user_data!=null){
					this.user_data= user_data;
					console.log(user_data.id)
						this.get_offers(user_data.id);
				}
				else{
					
					this.get_offers(null);
				}
			})
		
			this.get_stars();
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad HomePage');
  }
  get_offers(id){
		this.myservice.show_loader();
		this.myservice.load_get('getOffers/limit/4/id/'+id).subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				this.offers = data.result;
				console.log(this.offers);
			}
		});
	}
	/* get_profile(id,offer_id,service_id){
		 var obj = {'offers' : offer_id,'service_id' : service_id}
		this.navCtrl.push('ShopdetailPage',{'garage_id' : id,'page' :'offers' , 'offers':obj});
	} */
	get_profile(id,offer_id,service_id){
		this.navCtrl.push('Moreoffers');
	} 
	view_more(){
		this.navCtrl.push('Moreoffers');
	}
	edit_profile(){
		this.navCtrl.push('AddcarPage');
	}
	get_stars(){
		var i;
		var k;
		for(i=1;i<=5;i++){
			console.log('*');
			for(k=1;k<=i;k++){
			console.log('*');
				 
			}
		}
	}

}
