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.routeMap
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

@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)
            }

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