import { Component } from '@angular/core';
import { NavController, MenuController } from 'ionic-angular';
import { TokenService } from '../../providers/token-service';
import { HomePage } from '../home/home'

@Component({
    selector: 'page-login',
    providers: [TokenService],
    templateUrl: 'login.html'
})

export class LoginPage {

    constructor(
        public navCtrl: NavController,
        public menuCtrl: MenuController,
        public tokenService: TokenService
    ) {}

    ionViewDidLoad() {
        this.menuCtrl.enable(false);

        if (this.tokenService.tokenIsPresent()) {
            this.goToHome();
        }
    }

    // Signin odoo
    signin(): void {
        this.tokenService.getToken();
        this.goToHome();
    }

    // Go to home
    private goToHome(): void {
        this.navCtrl.setRoot(HomePage);
        this.menuCtrl.enable(true);
    }
}
