import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Main } from '../main/main'
import { AlertController } from 'ionic-angular';
import { VespotServiceProvider } from '../../providers/vespot-service/vespot-service';
import { ShareService } from '../../services/share/share';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  user:any;
  password:any;

  constructor(public navCtrl: NavController,
		public alertCtrl: AlertController,
		public vespotService: VespotServiceProvider,
    public shareService: ShareService) {

  }

  login() {
	let auth = this.user + ':' + this.password;

  this.vespotService.getDevices(auth)
	.subscribe(
      (data) => { // Success
        this.shareService.setDevices(data);
        this.shareService.setAuthToken(auth);
        this.navCtrl.setRoot(Main);
      },
      (error) =>{
        let alert = this.alertCtrl.create({
      title: 'Advertencia',
      subTitle: 'Usuario y Contraseña Incorrectos',
      buttons: ['OK']
    });
    alert.present();
      }
    );

  }

}
