package cl.homelogic.platform.navigation

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.navigation.NavDeepLink
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.toRoute
import cl.homelogic.platform.common.logging.Trace
import cl.homelogic.platform.common.logging.TreeRoots

inline fun <reified T : NavigationDestination> NavGraphBuilder.createRoute(
    transition: NavigationTransition = NavigationTransition.FLOW,
    deepLinks: List<NavDeepLink> = listOf(),
    crossinline content: @Composable (T) -> Unit,
) {
    composable<T>(
//        enterTransition = {
//            when (transition) {
//                NavigationTransition.FLOW -> slideInHorizontally()
//                NavigationTransition.SINGLE -> NavigationAnimations.verticalEnter
//            }
//        },
//        exitTransition = {
//            when (transition) {
//                NavigationTransition.FLOW -> slideOutHorizontally()
//                NavigationTransition.SINGLE -> NavigationAnimations.verticalExit
//            }
//        },
//        popEnterTransition = {
//            when (transition) {
//                NavigationTransition.FLOW -> NavigationAnimations.horizontalPopEnter
//                NavigationTransition.SINGLE -> NavigationAnimations.verticalPopEnter
//            }
//        },
//        popExitTransition = {
//            when (transition) {
//                NavigationTransition.FLOW -> slideOutHorizontally()
//                NavigationTransition.SINGLE -> NavigationAnimations.verticalPopExit
//            }
//        },
        deepLinks = deepLinks,
    ) { backStackEntry ->
        val route: T = remember { backStackEntry.toRoute() }
        val isFirstComposition = remember { true }
        if (isFirstComposition) {
            Trace.i(
                TreeRoots.Navigation,
                "Route created: ${
                    route::class
                        .qualifiedName
                        ?.split(".")
                        ?.takeLast(2)
                        ?.joinToString(".") ?: route::class.simpleName
                }",
            )
            content(route)
        }
    }
}
