package me.lucasmenendez.myrecipesapp.activities;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import me.lucasmenendez.myrecipesapp.R;
import me.lucasmenendez.myrecipesapp.helpers.Dialog;
import me.lucasmenendez.myrecipesapp.helpers.Intenter;
import me.lucasmenendez.myrecipesapp.presenters.LoginPresenter;

public class LoginActivity extends AppCompatActivity {
	private LoginPresenter loginPresenter;

	private EditText edUsername;
	private EditText edPassword;
	private Button bLoginSubmit;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);

		this.loginPresenter = new LoginPresenter(this);

		this.edUsername = (EditText) findViewById(R.id.edUsername);
		this.edPassword = (EditText) findViewById(R.id.edPassword);
		this.bLoginSubmit = (Button) findViewById(R.id.bLoginSubmit);

		this.bLoginSubmit.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				doLogin(view);
			}
		});
	}

	public void doLogin(View view) {
		String username = this.edUsername.getText().toString();
		String password = this.edPassword.getText().toString();
		this.loginPresenter.doLogin(username, password);
	}

	public void successLogin() {
		Dialog.toast(R.string.login_wellcome);
		Intenter.clearNavigateTo(RecipesListActivity.class);
	}

	public void failedLogin() {

	}
}
