import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { first } from 'rxjs/operators';
import {NavController} from "ionic-angular";
import { HomePage } from "../home/home";

@Component({templateUrl: 'mock-login.html'})
export class MockLoginPage implements OnInit {
    loginForm: FormGroup;
    loading = false;
    submitted = false;
    returnUrl: string;

    constructor(
        private formBuilder: FormBuilder,
         public navCtrl: NavController
    ) {
        
    }

    ngOnInit() {
        this.loginForm = this.formBuilder.group({
            username: ['', Validators.required],
            password: ['', Validators.required]
        });
    }

    // convenience getter for easy access to form fields
    get f() { return this.loginForm.controls; }

    onSubmit() {
        this.submitted = true;

        // stop here if form is invalid
        if (this.loginForm.invalid) {
            return;
        }

        else{
            console.log('loginform control',this.loginForm);
            if(this.loginForm.value['username'].toLowerCase() == 'test' && this.loginForm.value['password'].toLowerCase() == 'test' )
            this.navCtrl.setRoot(HomePage);
        }
    }
}
