package com.yono.messeripos;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.ProgressBar;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textview.MaterialTextView;
import com.yono.messeripos.models.MainViewModels;
import com.yono.messeripos.models.UsersModels;
import com.yono.messeripos.response.DataResponse;
import com.yono.messeripos.utils.Utils;

public class LoginActivity extends AppCompatActivity {

    MainViewModels mainViewModels;
    SharedPreferences sharedPreferences;

    //State
    LoginState loginState;
    RegisterState registerState;

    MaterialButton btnSignin;
    MaterialButton btnSignup, btnSignIn;
    public static View invalidUser;
    public static View activateEmail;

    Utils utils;

    MaterialTextView tvForgotPassword;

    private String TAG = "MainActivity";

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

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window w = getWindow();
            w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }

        mainViewModels = ViewModelProviders.of(this).get(MainViewModels.class);

//        registerSheetLayout = findViewById(R.id.ConstraintRegisterLayout);

//        sheetBehavior2 = BottomSheetBehavior.from(registerSheetLayout);

        //button on click to form register
//        btnSignup.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (sheetBehavior2.getState() != BottomSheetBehavior.STATE_EXPANDED) {
//                    sheetBehavior2.setState(BottomSheetBehavior.STATE_EXPANDED);
//                    registerSheetLayout.setMaxHeight(height - 100);
//                } else {
//                    sheetBehavior2.setState(BottomSheetBehavior.STATE_COLLAPSED);
//                }
//            }
//        });

//        bindUI
        btnSignIn = findViewById(R.id.signInButtonDashboardLogin);
        btnSignup = findViewById(R.id.signUpButtonDashboardLogin);

//        //button on click to form register
//        btnSignup.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (sheetBehavior2.getState() != BottomSheetBehavior.STATE_EXPANDED) {
//                    sheetBehavior2.setState(BottomSheetBehavior.STATE_EXPANDED);
//                    registerSheetLayout.setMaxHeight(height - 100);
//                } else {
//                    sheetBehavior2.setState(BottomSheetBehavior.STATE_COLLAPSED);
//                }
//            }
//        });

//        session login
        sharedPreferences = getSharedPreferences(SplashScreen.MY_SHARED_PREFERENCES, Context.MODE_PRIVATE);

//        button login on click
        btnSignIn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri data = LoginActivity.this.getIntent().getData();
                if (data != null && data.isHierarchical()) {
                    String uri = LoginActivity.this.getIntent().getDataString();
                    Log.d("TAG", "onBackPressed: "+uri);
                }
                loginState = new LoginState(LoginActivity.this, mainViewModels);
                loginState.setCancelable(false);
                loginState.show(getSupportFragmentManager(), loginState.getTag());
            }
        });

        btnSignup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                registerState = new RegisterState(LoginActivity.this,mainViewModels);
                registerState.setCancelable(false);
                registerState.show(getSupportFragmentManager(),registerState.getTag());
            }
        });
    }
}
