package com.fastest.pass.welcome.utils

import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.fastest.pass.R
import com.fastest.pass.welcome.presentation.ui.fragment.WelcomeFragment

class WelcomeNavigation {

    fun navigateTo(welcomeFragment: WelcomeFragment) {
        welcomeFragment.lifecycleScope.launchWhenStarted {
            welcomeFragment.viewModel.router.collect {
                when (it) {
                    is WelcomeNavigationRoute.OpenLogin -> {
//                        welcomeFragment.findNavController().popBackStack()
                        welcomeFragment.findNavController().navigate(R.id.loginFragment)
                    }

                    is WelcomeNavigationRoute.OpenSignup -> {
//                        welcomeFragment.findNavController().popBackStack()
                        welcomeFragment.findNavController().navigate(R.id.signupFragment)
                    }

                    else -> {}
                }

                welcomeFragment.viewModel.navigateTo(WelcomeNavigationRoute.NoneScreen)
            }
        }
    }
}