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


@IonicPage()
@Component({
  selector: 'page-moreoffers',
  templateUrl: 'moreoffers.html',
})
export class Moreoffers {
	offers=[];
	user_data:any;
	//page =5;
	page: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){
					this.user_data= user_data;
					this.get_offers();
				}
			})
			
  }

	ionViewDidLoad() {
		console.log('ionViewDidLoad Moreoffers');
	}
  
	doRefresh(refresher) {
		console.log('Begin async operation', refresher);

		setTimeout(() => {
			this.get_offers();
			console.log('Async operation has ended');
			refresher.complete();
		}, 2000);
	}


  shopdetail()
  {
    this.navCtrl.push('ShopdetailPage');
  } 
    get_offers(){
		this.myservice.show_loader();
		this.myservice.load_get('getOffers/id/'+this.user_data.id).subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				//this.offers = data.result;
				console.log(this.page)
				//if(data.result.length ==this.page)
					this.offers = data.result;
				//else
					//this.offers = this.offers.concat(data.result);
				console.log(this.offers);
			}
		});
	}    
	
 
		/* doInfinite(infiniteScroll) {
		console.log('Begin async operation');
		 
		this.page +=5;
		setTimeout(() => {
			this.get_offers();
			console.log('Async operation has ended');
			infiniteScroll.complete();
		}, 500);
		
	} */
		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});
	}

}
