package com.example.apk_deteksi_kualitas_telur

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.example.apk_deteksi_kualitas_telur.Ui.Activity.ObjekDeteksiMainActivity
import com.example.apk_deteksi_kualitas_telur.Ui.Fragment.ClassificationFragment
import com.example.apk_deteksi_kualitas_telur.Ui.Fragment.HomeFragment
import com.example.apk_deteksi_kualitas_telur.Ui.Fragment.LocationFragment
import com.example.apk_deteksi_kualitas_telur.Ui.Fragment.ProfileFragment
import com.example.apk_deteksi_kualitas_telur.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        replaceFragment(HomeFragment())
        navigationButton()
    }

    private fun navigationButton() {
        binding.fabClassification.setOnClickListener {
            val intent = Intent(this, ObjekDeteksiMainActivity::class.java)
            startActivity(intent)
        }
        binding.bottomNavigationView.setOnItemSelectedListener {
            when (it.itemId) {
                R.id.homeFragment -> replaceFragment(HomeFragment())
                R.id.locationFragment -> replaceFragment(LocationFragment())
                R.id.classificationFragment -> replaceFragment(ClassificationFragment())
                R.id.profileFragment -> replaceFragment(ProfileFragment())
                else -> {
                }
            }
            true
        }
    }

    private fun replaceFragment(fragment: Fragment) {
        val fragmentManager = supportFragmentManager
        val fragmentTransaction = fragmentManager.beginTransaction()
        fragmentTransaction.replace(R.id.frame_layout, fragment)
        fragmentTransaction.commit()
    }
}



