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._component.BackCloseComponent
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

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

    BackCloseComponent(navController)

    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.navigate(routeMap(effect.lat?.toString(), effect.lng?.toString(), effect.spotId))
                ContentContract.Effect.Navigation.ToBack -> navController.popBackStack()
                ContentContract.Effect.Navigation.ToPrintJobList -> navController.navigate(routePrintJobs())
            }
        }
    )
}