package com.fastest.pass.forgotpassword.utils

import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.fastest.pass.R
import com.fastest.pass.forgotpassword.presentation.ui.ForgotPasswordFragment

class ForgotPasswordNavigation {

    fun navigate(forgotPasswordFragment: ForgotPasswordFragment) {
        forgotPasswordFragment.lifecycleScope.launchWhenStarted {
            forgotPasswordFragment.viewmodel.router.collect { router ->
                when (router) {
                    ForgotPasswordRoute.OpenNoneScreen -> {}
                    ForgotPasswordRoute.GoBackToLogin -> {
                        forgotPasswordFragment.findNavController().popBackStack()
                    }
                    ForgotPasswordRoute.OpenForgotVerifyScreen -> {
                        forgotPasswordFragment.findNavController().navigate(R.id.forgotPasswordVerifyFragment)
                    }
                }

                forgotPasswordFragment.viewmodel.navigateTo(ForgotPasswordRoute.OpenNoneScreen)
            }
        }
    }
}