package com.fastest.pass.splash.utils

import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.fastest.pass.R
import com.fastest.pass.splash.presentation.ui.SplashFragment

class SplashNavigation {

    fun navigate(splashFragment: SplashFragment){
        splashFragment.lifecycleScope.launchWhenStarted {
            splashFragment.viewModel.router.collect { router ->
                when (router) {
                    SplashRoute.OpenLogin -> {
                        splashFragment.findNavController().popBackStack()
                        splashFragment.findNavController().navigate(R.id.loginFragment)
                    }
                    SplashRoute.OpenWelcome -> {
                        splashFragment.findNavController().popBackStack()
                        splashFragment.findNavController().navigate(R.id.welcomeFragment)
                    }
                    SplashRoute.NoneScreen -> {}
                }

                splashFragment.viewModel.navigateTo(SplashRoute.NoneScreen)
            }
        }
    }

}