package ru.fincode.tsudesk.core.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavOptionsBuilder


fun NavController.navigateToTopLevel(destination: TopLevelDestination) {
    val route = destination.toRoute()
    navigate(route) {
        popUpTo(graph.findStartDestination().id) {
            saveState = true
        }
        launchSingleTop = true
        restoreState = true
    }
}

fun NavController.navigateRoute(
    route: AppRoute,
    builder: (NavOptionsBuilder.() -> Unit)? = null
) {
    if (builder == null) {
        navigate(route)
    } else {
        navigate(route, builder)
    }
}
