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.routePrintJobs
import com.isidroid.c23.ui.navigation.routeRenderPreview
import com.isidroid.c23.ui.screen.content.ContentContract
import com.isidroid.c23.ui.screen.content.ContentScreen
import com.isidroid.c23.ui.screen.content.ContentViewModel
import com.isidroid.c23.ui.screen.home.HomeScreen
import com.isidroid.c23.ui.screen.home.HomeViewModel
import com.isidroid.core.ext.navigateSingleTopTo

@Composable
fun ContentScreenDestination(navController: NavHostController) {
    val viewModel: ContentViewModel = hiltViewModel()

    ContentScreen(
        state = viewModel.viewState,
        effectFlow = viewModel.effect,
        onEventSent = { event -> viewModel.setEvent(event) },
        onNavigationRequested = { effect ->
            when (effect) {
                is ContentContract.Effect.Navigation.ToRenderPreview -> navController.navigate(routeRenderPreview(uris = effect.uris))
                is ContentContract.Effect.Navigation.ToMap -> navController.navigateSingleTopTo(routeMap(effect.lat?.toString(), effect.lng?.toString(), effect.spotId))
                ContentContract.Effect.Navigation.ToBack -> navController.popBackStack()
                ContentContract.Effect.Navigation.ToPrintJobList -> navController.navigate(routePrintJobs())
            }
        }
    )
}