@file:Suppress("HardCodedStringLiteral")

package eu.gaudian.translator.view.settings

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.navigation
import eu.gaudian.translator.view.composable.Screen
import eu.gaudian.translator.view.hints.HintDefinition
import eu.gaudian.translator.view.hints.HintScreen
import eu.gaudian.translator.view.hints.HintsOverviewScreen

// Defines the routes for the settings graph to avoid using raw strings
object SettingsRoutes {
    const val TTS_OPTIONS = "settings_tts_options"
    const val LOGS = "settings_logs"
    const val LIST = "settings_list"
    const val ABOUT = "settings_about"
    const val API_KEY = "settings_api_key"
    const val LAYOUT_OPTIONS = "settings_layout_options"
    const val CUSTOM_TRANSLATION_PROMPT = "settings_custom_translation_prompt"
    const val LANGUAGE_OPTIONS = "settings_language_options"
    const val DICTIONARY_OPTIONS = "settings_dictionary_options"
    const val VOCABULARY_OPTIONS = "settings_vocabulary_options"
    const val VOCABULARY_PROMPT_OPTIONS = "settings_vocabulary_prompt_options"
    const val VOCABULARY_REPOSITORY_OPTIONS = "settings_vocabulary_repository_options"
    const val EXERCISE_OPTIONS = "settings_exercise_options"
    // ADD THIS LINE
    const val GENERAL = "settings_general"
    const val ADD_MODEL = "settings_add_model/{providerKey}"
    const val HINTS_OVERVIEW = "settings_hints_overview"
    const val HINTS_CATEGORIES = "settings_hints_categories"
    const val HINTS_DICTIONARY = "settings_hints_dictionary"
    const val HINTS_IMPORT = "settings_hints_import"
    const val HINTS_SORTING = "settings_hints_sorting"
    const val HINTS_STAGES = "settings_hints_stages"
    const val HINTS_TRANSLATION = "settings_hints_translation"
    const val HINTS_SCAN = "settings_hints_scan"
    const val HINTS_API = "settings_hints_api"
    const val HINTS_VOCABULARY_PROGRESS = "settings_hints_vocabulary_progress"

    const val DEV_OPTIONS = "settings_dev_options"
    const val THEME_PREVIEW = "settings_theme_preview"
}

// This function builds the nested navigation graph for all settings screens
fun NavGraphBuilder.settingsGraph(navController: NavController) {
    navigation(
        startDestination = SettingsRoutes.LIST,
        route = Screen.Settings.route // The route for the entire settings flow
    ) {
        composable(SettingsRoutes.LIST) {
            MainSettingsScreen(navController = navController)
        }
        composable(SettingsRoutes.ABOUT) {
            AboutScreen(navController = navController)
        }
        composable(SettingsRoutes.GENERAL) {
            GeneralSettingsScreen(navController = navController)
        }
        composable(SettingsRoutes.API_KEY) {
            ApiKeyScreen(navController = navController)
        }
        composable(SettingsRoutes.ADD_MODEL) { backStackEntry ->
            val providerKey = backStackEntry.arguments?.getString("providerKey") ?: ""
            AddModelScreen(navController = navController, providerKey = providerKey)
        }
        composable(SettingsRoutes.LAYOUT_OPTIONS) {
            LayoutOptionsScreen(navController = navController)
        }
        composable(SettingsRoutes.CUSTOM_TRANSLATION_PROMPT) {
            TranslationSettingsScreen(
                navController = navController
            )
        }
        composable(SettingsRoutes.LANGUAGE_OPTIONS) {
            LanguageOptionsScreen(navController = navController)
        }
        composable(SettingsRoutes.DICTIONARY_OPTIONS) {
            DictionaryOptionsScreen(
                navController = navController
            )
        }
        composable(SettingsRoutes.VOCABULARY_OPTIONS) {
            VocabularyProgressOptionsScreen(navController = navController)
        }
        composable(SettingsRoutes.VOCABULARY_PROMPT_OPTIONS) {
            CustomVocabularyPromptScreen(navController = navController)
        }
        composable(SettingsRoutes.VOCABULARY_REPOSITORY_OPTIONS) {
            VocabularyRepositoryOptionsScreen(navController = navController)
        }
        composable(SettingsRoutes.EXERCISE_OPTIONS) {
            ExerciseSettingsScreen(navController)
        }
        composable(SettingsRoutes.LOGS) {
            LogsScreen(navController = navController)
        }
        composable(SettingsRoutes.TTS_OPTIONS) {
            TextToSpeechSettingsScreen(navController = navController)
        }
        composable(SettingsRoutes.THEME_PREVIEW) {
            ThemePreviewScreen(navController = navController)
        }
        composable(SettingsRoutes.HINTS_OVERVIEW) {
            HintsOverviewScreen(navController = navController)
        }
        composable(SettingsRoutes.HINTS_CATEGORIES) {
            HintScreen(navController, HintDefinition.CATEGORY)
        }
        composable(SettingsRoutes.HINTS_DICTIONARY) {
            HintScreen(navController, HintDefinition.DICTIONARY_OPTIONS)
        }
        composable(SettingsRoutes.HINTS_IMPORT) {
            HintScreen(navController, HintDefinition.VOCABULARY_GENERATE_AI)
        }
        composable(SettingsRoutes.HINTS_SORTING) {
            HintScreen(navController, HintDefinition.SORTING)
        }
        composable(SettingsRoutes.HINTS_STAGES) {
            HintScreen(navController, HintDefinition.LEARNING_STAGES)
        }
        composable(SettingsRoutes.HINTS_TRANSLATION) {
            HintScreen(navController, HintDefinition.TRANSLATION)
        }
        composable(SettingsRoutes.HINTS_SCAN) {
            HintScreen(navController, HintDefinition.ADD_MODEL_SCAN)
        }
        composable(SettingsRoutes.HINTS_API) {
            HintScreen(navController, HintDefinition.API_KEY)
        }
        composable(SettingsRoutes.HINTS_VOCABULARY_PROGRESS) {
            HintScreen(navController, HintDefinition.VOCABULARY_PROGRESS)
        }
    }
}