package com.fastest.pass.home.utils

import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.fastest.pass.R
import com.fastest.pass.home.presentation.ui.fragment.AddNewItemsFragment

class AddNewItemsNavigation {
    fun navigate(addNewItemsFragment: AddNewItemsFragment) {
        addNewItemsFragment.lifecycleScope.launchWhenStarted {
            addNewItemsFragment.viewmodel.router.collect { router ->
                when (router) {
                    AddNewItemsRoute.Go_Back_Home -> {
                        addNewItemsFragment.findNavController().popBackStack()
                    }
                    AddNewItemsRoute.OpenNewItemFormScreen -> {
                        addNewItemsFragment.findNavController().navigate(R.id.newItemFormFragment)
                    }
                    AddNewItemsRoute.OpenNoneScreen -> {}
                }

                addNewItemsFragment.viewmodel.navigateTo(AddNewItemsRoute.OpenNoneScreen)
            }
        }
    }
}