package com.kaviz.heal_pharmacy;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.kaviz.heal_pharmacy.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    ActivityMainBinding binding;

    private static final String EMAIL = "heal@gmail.com";
    private static final String PASSWORD = "admin";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        makeFullScreen();
        setContentView(binding.getRoot());

        binding.loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String email = binding.emailText.getText().toString();
                String password = binding.passwordText.getText().toString();

                if (email.isEmpty()) {

                    binding.emailText.setError("Enter Email");

                } else if (password.isEmpty()) {

                    binding.passwordText.setError("Enter Password");

                } else if (!email.equals(EMAIL)) {

                    Toast.makeText(MainActivity.this, "Wrong Email", Toast.LENGTH_SHORT).show();

                } else if (!password.equals(PASSWORD)) {

                    Toast.makeText(MainActivity.this, "Wrong Password", Toast.LENGTH_SHORT).show();

                } else {

                    Toast.makeText(MainActivity.this, "Login Successful!", Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(MainActivity.this, OrdersActivity.class));
                    finishAffinity();

                }

            }
        });

    }

    // For hide the status bar.
    private void makeFullScreen() {

        //getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // Hide the app bar.
        if (getSupportActionBar() != null) {

            getSupportActionBar().hide();

        }

    }

}