package net.micode.notes.ui;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import net.micode.notes.R;

public class LoginActivity extends Activity {
    private EditText accountEdict;
    private EditText passwordEdict;
    private Button login;
    private Button cancel;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_login);
        accountEdict = (EditText) findViewById(R.id.account);
        accountEdict.setSingleLine();
        passwordEdict = (EditText) findViewById(R.id.password);
        passwordEdict.setSingleLine();
        login = (Button) findViewById(R.id.login);
        cancel = (Button) findViewById(R.id.cancel);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(LoginActivity.this,R.string.app_already_quit,Toast.LENGTH_LONG).show();
                finish();
            }
        });
        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String account = accountEdict.getText().toString();
                String password = passwordEdict.getText().toString();


                if(account.equals("czx") && password.equals("123456")){
                    AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
                    builder.setMessage(getString(R.string.Loading));
                    builder.setCancelable(true);
                    AlertDialog progressDialog = builder.create();
                    progressDialog.show();

                    Intent intent = new Intent(LoginActivity.this,NotesListActivity.class);
                    startActivity(intent);
                    finish();
                }else {
                    Toast.makeText(LoginActivity.this, R.string.invalid,Toast.LENGTH_SHORT).show();
                }
            }
        });
//        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
//            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
//            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
//            return insets;
//        });
    }
}