package com.example.triphelper.view.navigation

import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.example.triphelper.model.Advice
import com.example.triphelper.view.Auth.Auth
import com.example.triphelper.view.LawScreen.DescriptionLaws
import com.example.triphelper.view.MainScreen.LawScreen
import com.example.triphelper.view.MainScreen.MainScreen
import com.example.triphelper.view.ProfileScreen.ProfileUser
import com.example.triphelper.view.Registration.Registration
import com.example.triphelper.view.RouteScreens.AdviceScreen
import com.example.triphelper.view.RouteScreens.AttractionsDesc
import com.example.triphelper.view.RouteScreens.ChoiceLocation
import com.example.triphelper.view.RouteScreens.ChoiceTour
import com.example.triphelper.view.RouteScreens.HotelsDesc
import com.example.triphelper.view.RouteScreens.RestaurantsDesc
import com.example.triphelper.view.RouteScreens.Tours
import com.example.triphelper.view.SplashScreen.SplashScreen

@RequiresApi(Build.VERSION_CODES.O)
@Composable
fun Navigation(controller: NavHostController, barsIsVisible: MutableState<Boolean>,
               iconsLawIsActivity: MutableState<Boolean>, iconsProfileIsActivity: MutableState<Boolean>,
               iconsAdviceIsActivity: MutableState<Boolean>,iconsMainIsActivity: MutableState<Boolean>, iconsRoutsIsActivity: MutableState<Boolean>) {
    NavHost(navController = controller,
        startDestination = NavigationRoutes.CH_LOC)
    {
        composable( NavigationRoutes.SPLASH){
            barsIsVisible.value = false
            SplashScreen(controller)
        }
        composable( NavigationRoutes.AUTH){
            barsIsVisible.value = false
            Auth(controller)
        }
        composable(NavigationRoutes.REG){
            barsIsVisible.value = false
            Registration(controller)
        }
        composable(NavigationRoutes.MAIN){
            barsIsVisible.value = true
            iconsLawIsActivity.value = false
            iconsAdviceIsActivity.value = false
            iconsProfileIsActivity.value = false
            iconsMainIsActivity.value = false
            iconsRoutsIsActivity.value = false
            MainScreen(controller, iconsMainIsActivity)
        }
        composable(NavigationRoutes.LAW){
            barsIsVisible.value = true
            iconsLawIsActivity.value = false
            iconsAdviceIsActivity.value = false
            iconsProfileIsActivity.value = false
            iconsMainIsActivity.value = false
            iconsRoutsIsActivity.value = false
            LawScreen(controller, iconsLawIsActivity)
        }
        composable(route =  "${NavigationRoutes.DESCLAW}/{title}"){
            backStackEntry ->
            val title = backStackEntry.arguments?.getString("title")
            barsIsVisible.value = true
            iconsLawIsActivity.value = false
            iconsAdviceIsActivity.value = false
            iconsProfileIsActivity.value = false
            iconsMainIsActivity.value = false
            iconsRoutsIsActivity.value = false
            if (title != null) {
                DescriptionLaws(controller, iconsLawIsActivity, title)
            }
        }
        composable(NavigationRoutes.CH_LOC){
            barsIsVisible.value = true
            iconsLawIsActivity.value = false
            iconsAdviceIsActivity.value = false
            iconsProfileIsActivity.value = false
            iconsMainIsActivity.value = false
            iconsRoutsIsActivity.value = false
            ChoiceLocation(controller, iconsRoutsIsActivity)
        }
        composable(route =  "${NavigationRoutes.CH_TOUR}/{titleCity}"){
            backStackEntry ->
            val titleCity = backStackEntry.arguments?.getString("titleCity")
            barsIsVisible.value = true
            iconsLawIsActivity.value = false
            iconsAdviceIsActivity.value = false
            iconsProfileIsActivity.value = false
            iconsMainIsActivity.value = false
            iconsRoutsIsActivity.value = false
            if (titleCity != null) {
                ChoiceTour(controller, iconsRoutsIsActivity, titleCity)
            }
        }
        composable(route =  "${NavigationRoutes.TOURS}/{titleCity}/{numberToure}"){
                backStackEntry ->
            val titleCity = backStackEntry.arguments?.getString("titleCity")
            val numberToure = backStackEntry.arguments?.getString("numberToure")
            barsIsVisible.value = true
            iconsLawIsActivity.value = false
            iconsAdviceIsActivity.value = false
            iconsProfileIsActivity.value = false
            iconsMainIsActivity.value = false
            iconsRoutsIsActivity.value = false
            if (titleCity != null && numberToure != null) {
                Tours(controller, iconsRoutsIsActivity, titleCity, numberToure)
            }
        }
        composable(route =  "${NavigationRoutes.ATT_DESC}/{idAttractions}/{titleAttractions}"){
                backStackEntry ->
            val idAttractions = backStackEntry.arguments?.getString("idAttractions")
            val titleAttractions = backStackEntry.arguments?.getString("titleAttractions")
            barsIsVisible.value = true
            iconsLawIsActivity.value = false
            iconsAdviceIsActivity.value = false
            iconsProfileIsActivity.value = false
            iconsMainIsActivity.value = false
            iconsRoutsIsActivity.value = false
            if (idAttractions != null && titleAttractions != null) {
                AttractionsDesc(controller, iconsRoutsIsActivity, idAttractions.toInt(), titleAttractions)
            }
        }
        composable(route =  "${NavigationRoutes.HOTEL_DESC}/{idHotels}/{titleHotels}"){
                backStackEntry ->
            val idHotels = backStackEntry.arguments?.getString("idHotels")
            val titleHotels = backStackEntry.arguments?.getString("titleHotels")
            barsIsVisible.value = true
            iconsLawIsActivity.value = false
            iconsAdviceIsActivity.value = false
            iconsProfileIsActivity.value = false
            iconsMainIsActivity.value = false
            iconsRoutsIsActivity.value = false
            if (idHotels != null && titleHotels != null) {
                HotelsDesc(controller, iconsRoutsIsActivity, idHotels.toInt(), titleHotels)
            }
        }
        composable(route =  "${NavigationRoutes.REST_DESC}/{idRest}/{titleRest}"){
                backStackEntry ->
            val idRest = backStackEntry.arguments?.getString("idRest")
            val titleRest = backStackEntry.arguments?.getString("titleRest")
            barsIsVisible.value = true
            iconsLawIsActivity.value = false
            iconsAdviceIsActivity.value = false
            iconsProfileIsActivity.value = false
            iconsMainIsActivity.value = false
            iconsRoutsIsActivity.value = false
            if (idRest != null && titleRest != null) {
                RestaurantsDesc(controller, iconsRoutsIsActivity, idRest.toInt(), titleRest)
            }
        }
        composable(NavigationRoutes.ADVICE){
            barsIsVisible.value = true
            iconsLawIsActivity.value = false
            iconsAdviceIsActivity.value = false
            iconsProfileIsActivity.value = false
            iconsMainIsActivity.value = false
            iconsRoutsIsActivity.value = false
            AdviceScreen(controller, iconsAdviceIsActivity)
        }
        composable(NavigationRoutes.PROF_USER){
            barsIsVisible.value = true
            iconsLawIsActivity.value = false
            iconsAdviceIsActivity.value = false
            iconsProfileIsActivity.value = false
            iconsMainIsActivity.value = false
            iconsRoutsIsActivity.value = false
            ProfileUser(controller, iconsProfileIsActivity)
        }
    }
}