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.domain.model.Screen
import com.fastest.pass.home.presentation.ui.fragment.BrowseFragment

class NewItemBrowseNavigation {

    fun navigate(newItemBrowseFragment: NewItemBrowseFragment, activity: FragmentActivity) {
        newItemBrowseFragment.lifecycleScope.launchWhenStarted {
            newItemBrowseFragment.viewmodel.router.collect { router ->
                when (router) {
                    NewItemBrowseRoute.GoBackToBrowseScreen -> {
//                        newItemBrowseFragment.findNavController().popBackStack()

                        val browseFragment = BrowseFragment()
                        activity.supportFragmentManager.beginTransaction()
                            .replace(R.id.fragment_container_view, browseFragment)
                            .commit()
                    }
                    NewItemBrowseRoute.OpenNoneScreen -> {}
                }

                newItemBrowseFragment.viewmodel.navigateTo(NewItemBrowseRoute.OpenNoneScreen)
            }
        }
    }

}