package com.fastest.pass.browse.utils

import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.fastest.pass.R
import com.fastest.pass.browse.presentation.ui.fragment.NewItemBrowseFragment
import com.fastest.pass.dashboard.presentation.ui.component.BottomTab
import com.fastest.pass.home.presentation.ui.fragment.BrowseFragment

class BrowseNavigation {

    fun navigate(browseFragment: BrowseFragment, activity: FragmentActivity) {
        browseFragment.lifecycleScope.launchWhenStarted {
            browseFragment.viewmodel.router.collect { router ->
                when (router) {
                    BrowseRoute.GoBackToBrowseScreen -> {
                        browseFragment.findNavController().popBackStack()
                    }
                    BrowseRoute.OpenNewItemBrowseScreen -> {
//                        browseFragment.findNavController().navigate(R.id.newItemBrowseFragment)

                        val newItemBrowseFragment1 = NewItemBrowseFragment()
                        activity.supportFragmentManager.beginTransaction()
                            .replace(R.id.fragment_container_view, newItemBrowseFragment1)
                            .addToBackStack("NewItemBrowseFragment")
                            .commit()
                    }
                    BrowseRoute.OpenNoneScreen -> {}
                }
                browseFragment.viewmodel.navigateTo(BrowseRoute.OpenNoneScreen)
            }
        }
    }

}

