package ru.fincode.tsudesk.presentation.main

import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hasRoute
import ru.fincode.tsudesk.core.navigation.AppRoute
import ru.fincode.tsudesk.core.navigation.TopLevelDestination

fun selectedTopLevel(entry: NavBackStackEntry?): TopLevelDestination {
    val dest: NavDestination = entry?.destination ?: return TopLevelDestination.SCHEDULE

    return when {
        dest.hasRoute<AppRoute.Schedule>() || dest.hasRoute<AppRoute.ScheduleDetails>() ->
            TopLevelDestination.SCHEDULE

        dest.hasRoute<AppRoute.News>() || dest.hasRoute<AppRoute.NewsDetails>() ->
            TopLevelDestination.NEWS

        dest.hasRoute<AppRoute.Progress>() ->
            TopLevelDestination.PROGRESS

        dest.hasRoute<AppRoute.Settings>() ->
            TopLevelDestination.SETTINGS

        else -> TopLevelDestination.SCHEDULE
    }
}

fun shouldShowBottomBar(entry: NavBackStackEntry?): Boolean {
    val dest: NavDestination = entry?.destination ?: return false
    return !dest.hasRoute<AppRoute.Splash>()
}