package ru.fincode.tsudesk.presentation.navigation

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import ru.fincode.tsudesk.core.navigation.AppRoute
import ru.fincode.tsudesk.core.navigation.navigateRoute
import ru.fincode.tsudesk.feature.news.presentation.screen.NewsRoute
//import ru.fincode.tsudesk.feature.news.presentation.screen.NewsRoute
import ru.fincode.tsudesk.presentation.main.MainScaffold
import ru.fincode.tsudesk.feature.schedule.presentation.screen.ScheduleRoute
import ru.fincode.tsudesk.feature.splash.presentation.screen.SplashRoute

@Composable
fun AppNavHost(
    navController: NavHostController,
) {
    NavHost(
        navController = navController,
        startDestination = AppRoute.Splash
    ) {
        composable<AppRoute.Splash> {
            SplashRoute(
                onFinish = {
                    navController.navigateRoute(AppRoute.Main) {
                        popUpTo(AppRoute.Splash) { inclusive = true }
                        launchSingleTop = true
                    }
                }
            )
        }

        composable<AppRoute.Main> {
            val tabsNavController = rememberNavController()

            MainScaffold(
                navController = tabsNavController
            ) { innerModifier ->
                MainTabsNavHost(
                    navController = tabsNavController,
                    modifier = innerModifier
                )
            }
        }
    }
}

@Composable
private fun MainTabsNavHost(
    navController: NavHostController,
    modifier: Modifier = Modifier,
) {
    NavHost(
        navController = navController,
        startDestination = AppRoute.Schedule,
        modifier = modifier
    ) {
        composable<AppRoute.Schedule> {
            ScheduleRoute(modifier = Modifier.fillMaxSize())
        }

        composable<AppRoute.News> {
            NewsRoute(modifier = Modifier.fillMaxSize())
        }

        composable<AppRoute.Progress> {
            // ProgressRoute(modifier = Modifier)
        }

        composable<AppRoute.Settings> {
            // SettingsRoute(modifier = Modifier)
        }
    }
}