package com.proyek.akhir.kodel.ui.koperasi

import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.google.android.material.snackbar.Snackbar
import com.proyek.akhir.kodel.R
import com.proyek.akhir.kodel.ui.koperasi.beranda.history.HistoryKoperasiActivity
import com.proyek.akhir.kodel.ui.koperasi.berita.BeritaKoperasiActivity
import kotlinx.android.synthetic.main.activity_beranda.*
import kotlinx.android.synthetic.main.app_bar_beranda.*

class BerandaActivity : AppCompatActivity() {

    private lateinit var appBarConfiguration: AppBarConfiguration

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_beranda)
        setSupportActionBar(toolbar)

        toolbar.setTitleTextAppearance(this, R.style.SnigletTextAppearance)


        fab.setOnClickListener { view ->
            startActivity(Intent(this, BeritaKoperasiActivity::class.java))

        }

        val navController = findNavController(R.id.nav_host_fragment)
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        appBarConfiguration = AppBarConfiguration(
            setOf(
                R.id.nav_beranda,
                R.id.nav_informasi_koperasi,
                R.id.nav_produk_koperasi,
                R.id.nav_kupon_koperasi
            ), drawer_layout
        )
        setupActionBarWithNavController(navController, appBarConfiguration)
        nav_view.setupWithNavController(navController)
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        // Inflate the menu; this adds items to the action bar if it is present.
        menuInflater.inflate(R.menu.beranda, menu)
        return true
    }

    override fun onSupportNavigateUp(): Boolean {
        val navController = findNavController(R.id.nav_host_fragment)
        return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        if (item.itemId == R.id.action_settings) {
            startActivity(Intent(this, HistoryKoperasiActivity::class.java))
        }
        return true
    }
}
