import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams,Events,Platform,ModalController } from 'ionic-angular';
import {  FabContainer } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import {Myservice} from '../../providers/myservice';
import { Badge } from '@ionic-native/badge';

@IonicPage()
@Component({
  selector: 'page-tabs',
  templateUrl: 'tabs.html',
})
export class TabsPage {
	user_data:any;
	notify:any;
	services_offered:any;
  tab1: string = "LocationPage";
	tab2: string = "TabsPage";
  tab3: string = "HomePage";
  tab4: string = "NotificationPage";
  tab5: string = "AddcarPage";


  constructor(platform: Platform,public navCtrl: NavController, public navParams: NavParams, public storage: Storage, private myservice: Myservice,public events:Events,private badge: Badge,public modalCtrl: ModalController) {
	     
		/*  let backAction =  platform.registerBackButtonAction(() => {
        console.log("backPressed tabs page");
       platform.exitApp();
        backAction();
      },2) */
		this.storage.get('user_data').then((user_data) => {
				console.log(user_data);
				if(user_data){
					this.user_data= user_data;
					console.log("noti");
					this.get_notifications();
					console.log("in tabs",this.notify);
					events.subscribe('user:notifications', userdetails => {	
						this.get_notifications();
					});
					
				}
			})
			this.get_services();
			
  }

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

  open_page(page,id){
	   let profileModal = this.modalCtrl.create(page, {'service_id': id});
   profileModal.present();
    //this.navCtrl.push(page,{'service_id': id});
    }
		get_services(){
		this.myservice.show_loader();
		this.myservice.load_get('getServices').subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				this.services_offered = data.data;
				console.log("tabs")
				console.log(this.services_offered)
			}
		});
	}	

  	get_notifications(){
			console.log("noti called")
			
		this.myservice.show_loader();
		this.myservice.load_get('getNotifications/id/'+this.user_data.id).subscribe(data => {
			this.myservice.hide_loader();
			if(data.status == 'success'){
				console.log(data.data.count)
				this.notify = data.data.count
				this.badge.set(this.notify);
				console.log("tabs")
				console.log("vl",this.notify)
			}
		});
	}	
 
  
}
