package com.fastest.pass.account.utils

import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.fastest.pass.R
import com.fastest.pass.account.presentation.ui.fragment.AccountFragment

class AccountNavigation {

    fun navigate(accountFragment: AccountFragment) {
        accountFragment.lifecycleScope.launchWhenStarted {
            accountFragment.viewmodel.router.collect { router ->
                when (router) {
                    AccountRoute.OpenLoginScreen -> {
                        accountFragment.findNavController().popBackStack()
                        accountFragment.findNavController().navigate(R.id.loginFragment)
                    }
                    AccountRoute.OpenNoneScreen -> {}
                }
                accountFragment.viewmodel.navigateTo(AccountRoute.OpenNoneScreen)
            }
        }
    }
}