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.routeSelectContent
import com.isidroid.c23.ui.screen.map.MapContract
import com.isidroid.c23.ui.screen.map.MapScreen
import com.isidroid.c23.ui.screen.map.MapViewModel
import com.isidroid.core.ext.navigateSingleTopTo


@Composable
fun MapScreenDestination(navController: NavHostController) {
    val viewModel: MapViewModel = hiltViewModel()

    MapScreen(
        state = viewModel.viewState,
        effectFlow = viewModel.effect,
        onEventSent = { event -> viewModel.setEvent(event) },
        spotResultStateFlow = viewModel.spotResultStateFlow,
        onNavigationRequested = { effect ->
            when (effect) {
                MapContract.Effect.Navigation.ToBack -> navController.popBackStack()
                MapContract.Effect.Navigation.ToSelectContent -> navController.navigateSingleTopTo(routeSelectContent())
            }
        },
    )
}