package com.project.ilsaenterprise;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.MenuItem;

import com.google.android.material.bottomnavigation.BottomNavigationView;

public class Home extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(getSupportActionBar() != null){
            getSupportActionBar().hide();
        }
        setContentView(R.layout.activity_home);
        BottomNavigationView layNav = findViewById(R.id.layoutNav);
        layNav.setItemIconTintList(null);
        layNav.setSelectedItemId(R.id.home);
        layNav.setOnNavigationItemSelectedListener(navListener);
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new Dashboard()).commit();
    }

    private final BottomNavigationView.OnNavigationItemSelectedListener navListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
        @SuppressLint("NonConstantResourceId")
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            Fragment selectedFragment = new Fragment();
            switch (item.getItemId()) {
                case R.id.navHome:
                    selectedFragment = new Dashboard();
                    break;
                case R.id.navChat:
                    selectedFragment = new Chat();
                    break;
                case R.id.navMap:
                    selectedFragment = new Geodata();
                    break;
                case R.id.navMonitoring:
                    selectedFragment = new Monitoring();
                    break;
                case R.id.navAccount:
                    selectedFragment = new Account();
                    break;
            }
            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.fragment_container, selectedFragment)
                    .commit();
            return true;
        }
    };
}