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


@IonicPage()
@Component({
  selector: 'page-viewoffers',
  templateUrl: 'viewoffers.html',
})
export class Viewoffers {

  currentIndex:any;
  slidertab:any;
  user_data:any;
  request_list:any;

  @ViewChild(Content) content: Content;
  @ViewChild('mySlider') slider: Slides;

  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.viewoffers()
			}else
				this.navCtrl.push('LoginPage');
	})
    let id = this.navParams.get("id");
    this.slidertab = id;
    console.log("id", id);
    setTimeout(() => {
    this.goToSlide(id);
    }, 500)
    this.slidertab = 0;
  }

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

  goToSlide(id) {
    this.slider.slideTo(id, 500);
    }
    
    slideChanged() {
    let currentIndex = this.slider.getActiveIndex();
    this.slidertab = currentIndex;
    console.log("Current index is", currentIndex);
    }

    details(id){
      this.navCtrl.push('VehicleDetailPage',{'pool_id': id});
    }
	addOffers(){
      this.navCtrl.push('Addoffers');
    }	
	edit_offers(id){
      this.navCtrl.push('Editoffers',{'id':id});
    }
	viewoffers(){
		this.myservice.show_loader();
		this.myservice.load_get('get_offers/id/'+this.user_data.id).subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				this.request_list = data.data;
				console.log(this.request_list);
			}
		});
	}
    

}
