package com.app.rewardapp.ui.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.InputType;
import android.util.DisplayMetrics;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import com.app.rewardapp.R;
import com.app.rewardapp.databinding.ActivityMainBinding;
import com.app.rewardapp.databinding.LayoutLanguageBinding;
import com.app.rewardapp.ui.fragments.Coins;
import com.app.rewardapp.ui.fragments.FragmentMain;
import com.app.rewardapp.ui.fragments.Invite;
import com.app.rewardapp.ui.fragments.Leaderboard;
import com.app.rewardapp.ui.fragments.Profile;
import com.app.rewardapp.ui.fragments.RatingDialogFragment;
import com.app.rewardapp.util.Session;
import com.bumptech.glide.Glide;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.textfield.TextInputLayout;
import com.google.firebase.FirebaseApp;
import com.google.firebase.messaging.FirebaseMessaging;
import com.makeramen.roundedimageview.RoundedImageView;

import java.util.Locale;


public class MainActivity extends AppCompatActivity {
    ActivityMainBinding binding;
    public static boolean isAllSdkInitialize = true;
    Session session;

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

        FirebaseMessaging.getInstance().subscribeToTopic("all");
        AdsSdkInitialize();

        session = new Session(this);
        session.setBoolean(session.ENABLE_SESSION, true);

        BottomNavigationView bottomNavigationView = findViewById(R.id.navigation);
        bottomNavigationView.setOnNavigationItemSelectedListener(menuItem -> {

            switch (menuItem.getItemId()) {
                default:
                    loadFragment(new FragmentMain());
                case R.id.navigation_home:
                    loadFragment(new FragmentMain());
                    return true;
                case R.id.navigation_invite:
                    loadFragment(new Invite());
                    return true;
                case R.id.navigation_coin:
                    loadFragment(new Coins());
                    return true;
                case R.id.navigation_leaderboard:
                    loadFragment(new Leaderboard());
                    return true;
                case R.id.navigation_profile:
                    loadFragment(new Profile());
                    return true;
            }
        });

        bottomNavigationView.setSelectedItemId(R.id.navigation_home);

    }

    private void AdsSdkInitialize() {
//        if (isAllSdkInitialize) {
//            try {
//                adNetwork = new AdNetwork.Initialize(MainActivity.this);
//                adNetwork.setAdMobAppId(getString(R.string.ADMOB_APPID));
//                adNetwork.setApplovinSdkKey(getString(R.string.APPLOVIN_SDK_KEY));
//                adNetwork.setStartAppId(App.getData().get(0).getStartappid());
//                adNetwork.setUnityGameId(App.getData().get(0).getUnityGameid());
//                adNetwork.buildAd();
//                isAllSdkInitialize=false;
//            }catch (Exception e){
//
//            }
//        }
    }


    private void loadFragment(Fragment fragment) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.container, fragment);
        transaction.addToBackStack(null);
        transaction.commit();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public void onBackPressed() {
        RatingDialogFragment dialog = RatingDialogFragment.newInstance();
        dialog.show(getSupportFragmentManager(), "rating_dialog");
    }


}
