package com.fastest.pass.forgotpassword.utils

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

class ForgotPasswordConfirmNavigation {

    fun navigate(forgotPasswordConfirmFragment: ForgotPasswordConfirmFragment) {
        forgotPasswordConfirmFragment.lifecycleScope.launchWhenStarted {
            forgotPasswordConfirmFragment.viewmodel.router.collect { router ->
                when (router) {
                    ForgotPasswordConfirmRoute.GoBackToForgotVerify -> {
                        forgotPasswordConfirmFragment.findNavController().popBackStack()
                    }
                    ForgotPasswordConfirmRoute.OpenNoneScreen -> {}
                    ForgotPasswordConfirmRoute.OpenLoginScreen -> {
                        forgotPasswordConfirmFragment.findNavController().navigate(
                            R.id.loginFragment,
                            null,
                            NavOptions.Builder()
                                .setPopUpTo(R.id.welcomeFragment, false)
                                .build()
                        )
                    }
                }

                forgotPasswordConfirmFragment.viewmodel.navigateTo(ForgotPasswordConfirmRoute.OpenNoneScreen)
            }
        }
    }
}