package com.fluxup.app;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class ForgotPasswordActivity extends AppCompatActivity {

    private EditText etEmail;
    private Button btnSend;
    private TextView tvBack;

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

        etEmail = findViewById(R.id.etForgotEmail);
        btnSend = findViewById(R.id.btnSendReset);
        tvBack = findViewById(R.id.tvForgotBack);

        btnSend.setOnClickListener(v -> {
            String email = etEmail.getText().toString();
            if (email.isEmpty()) {
                Toast.makeText(ForgotPasswordActivity.this, "Por favor insira o seu email", Toast.LENGTH_SHORT).show();
            } else if (!email.contains("@")) {
                Toast.makeText(ForgotPasswordActivity.this, "O email deve conter um '@'", Toast.LENGTH_SHORT).show();
            } else {
                UsuariosService.recuperarPalavraPasse(ForgotPasswordActivity.this, email, new UsuariosService.ServiceCallback<Void>() {
                    @Override
                    public void onSuccess(Void data) {
                        Toast.makeText(ForgotPasswordActivity.this, "Um email com instruções foi enviado.", Toast.LENGTH_SHORT).show();
                        finish();
                    }

                    @Override
                    public void onError(String error) {
                        Toast.makeText(ForgotPasswordActivity.this, "Erro: " + error, Toast.LENGTH_LONG).show();
                    }
                });
            }
        });

        tvBack.setOnClickListener(v -> finish());
    }
}
