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.Home
import com.isidroid.c23.ui.navigation.routeJobDetails
import com.isidroid.c23.ui.navigation.routeMap
import com.isidroid.c23.ui.screen.print_jobs.PrintJobsContract
import com.isidroid.c23.ui.screen.print_jobs.PrintJobsScreen
import com.isidroid.c23.ui.screen.print_jobs.PrintJobsViewModel
import com.isidroid.core.ext.navigateSingleTopTo

@Composable
fun PrintJobsScreenDestination(navController: NavHostController) {
    val viewModel: PrintJobsViewModel = hiltViewModel()

    PrintJobsScreen(
        state = viewModel.viewState,
        effectFlow = viewModel.effect,
        onEventSent = { event -> viewModel.setEvent(event) },
        onNavigationRequested = { effect ->
            when (effect) {
                PrintJobsContract.Effect.Navigation.ToBack -> navController.popBackStack()
                is PrintJobsContract.Effect.Navigation.ToDetails -> navController.navigate(routeJobDetails(id = effect.id))
                is PrintJobsContract.Effect.Navigation.ToMap -> navController.navigateSingleTopTo(routeMap(lat = effect.lat.toString(), lng = effect.lng.toString()), popupToRoute = Home.route)
            }
        },
    )
}