package com.syaroful.agrilinkvocpro.plant_disease_detection_feature.navigation

import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.syaroful.agrilinkvocpro.plant_disease_detection_feature.presentation.camera.CameraScreen
import com.syaroful.agrilinkvocpro.plant_disease_detection_feature.presentation.camera.CameraViewModel
import com.syaroful.agrilinkvocpro.plant_disease_detection_feature.presentation.detail.DetailScreen
import com.syaroful.agrilinkvocpro.plant_disease_detection_feature.presentation.history.DetailHistoryScreen
import com.syaroful.agrilinkvocpro.plant_disease_detection_feature.presentation.history.HistoryScreen
import com.syaroful.agrilinkvocpro.plant_disease_detection_feature.presentation.history.HistoryViewModel
import org.koin.androidx.compose.koinViewModel

@Composable
fun NavGraph(navController: NavHostController) {
    val cameraViewModel: CameraViewModel = koinViewModel()
    val historyViewModel: HistoryViewModel = koinViewModel()


    NavHost(navController, startDestination = "camera_screen") {
        composable("camera_screen") {
            CameraScreen(navController, cameraViewModel)
        }
        composable("detail_screen") {
            DetailScreen(
                cameraViewModel = cameraViewModel,
                onBack = { navController.popBackStack() }
            )
        }
        composable("history") {
            HistoryScreen(navController = navController, viewModel = historyViewModel)
        }
        composable(
            route = "detail-history/{id}",
            arguments = listOf(navArgument("id") { type = NavType.IntType })
        ) { backStackEntry ->
            val id = backStackEntry.arguments?.getInt("id") ?: return@composable

            DetailHistoryScreen(
                navController = navController,
                diagnosisId = id,
                viewModel = historyViewModel
            )
        }
    }
}