package com.fastest.pass.signup.utils

import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.fastest.pass.R
import com.fastest.pass.signup.presentation.ui.SignUpFragment

class SignUpNavigation {

    fun navigate(signUpFragment: SignUpFragment) {
        signUpFragment.lifecycleScope.launchWhenStarted {
            signUpFragment.viewmodel.router.collect { router ->
                when (router) {
                    SignUpRoute.GoBack -> {
                        signUpFragment.findNavController().popBackStack()
                    }
                    SignUpRoute.OpenNoneScreen -> {}
                    SignUpRoute.OpenMasterSignupScreen -> {
                        signUpFragment.findNavController().navigate(R.id.masterSignupFragment)
                    }
                    SignUpRoute.OpenLoginScreen -> {
                        signUpFragment.findNavController().navigate(R.id.loginFragment)
                    }
                }

                signUpFragment.viewmodel.navigateTo(SignUpRoute.OpenNoneScreen)
            }
        }
    }
}