package com.isidroid.c23.ui.navigation.destinations

import androidx.compose.runtime.Composable
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import com.isidroid.c23.ui.navigation.routeHome
import com.isidroid.c23.ui.navigation.routeMap
import com.isidroid.c23.ui.navigation.routeRenderPreview
import com.isidroid.c23.ui.navigation.routeSelectContent
import com.isidroid.c23.ui.screen.home.HomeContract
import com.isidroid.c23.ui.screen.home.HomeScreen
import com.isidroid.c23.ui.screen.home.HomeViewModel
import com.isidroid.core.ext.navigateSingleTopTo
import timber.log.Timber

@Composable
fun HomeScreenDestination(navController: NavHostController) {
    val viewModel: HomeViewModel = hiltViewModel()

    HomeScreen(
        state = viewModel.viewState,
        effectFlow = viewModel.effect,
        onNavigationRequested = { effect ->
            val route = when (effect) {
                HomeContract.Effect.Navigation.ToLogin -> TODO("Session is not implemented")
                HomeContract.Effect.Navigation.ToSelectContent -> routeSelectContent()
                is HomeContract.Effect.Navigation.ToSelectSpot -> routeMap(lat = effect.lat?.toString(), lng = effect.lng?.toString(), spotCode = effect.spotCode, uris = effect.uris)
                is HomeContract.Effect.Navigation.ToPreview -> routeRenderPreview(uris = effect.uris)
            }

            navController.navigateSingleTopTo(
                route = route,
                isLaunchSingleTop = true,
                isInclusive = true,
                popupToRoute = routeHome()
            )
        }
    )
}