package com.example.what_the_fantasy.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.*
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.IconButtonColors
import androidx.compose.material3.IconToggleButton
import androidx.compose.material3.NavigationBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.example.what_the_fantasy.R
import com.example.what_the_fantasy.ui.theme.*

@Composable
fun NavBar(onProfile : Boolean = false ,
           onFavorite : Boolean = false ,
           onAccueil : Boolean = false ,
           onQuiz : Boolean = false ,
           index:Int,
           navControllerProfil: (Int) -> Unit,
           navControllerFavorite:(Int) -> Unit,
           navControllerAccueil: (Int) -> Unit,
           navControllerQuiz: (Int) -> Unit,

           content : @Composable ()-> Unit ) {

    var theme by remember { mutableStateOf(true) }
    Column(
        modifier = Modifier
            .fillMaxSize()
    ) {
        NavigationBar(
            modifier = Modifier
                .fillMaxWidth(),
            containerColor = colorNavBar
        ) {
            Row(
                modifier = Modifier
                    .fillMaxWidth(),
                Arrangement.SpaceBetween,
                verticalAlignment = Alignment.Bottom
            ) {
                ButtonIconVectorInt(Icons.Rounded.AccountCircle,"Profile",navControllerProfil,index,onProfile)


                IconButton(onClick = { theme=!theme},
                    modifier = Modifier.size(60.dp)
                        .clip(RoundedCornerShape(0))
                ) {
                    Icon(painterResource(
                        if(theme)R.drawable.dark_mode_toggle_icon
                        else R.drawable.light_mode_toggle_icon),
                        contentDescription = "Dark mode",
                        modifier = Modifier.fillMaxSize(),
                        tint = Color.White
                    )
                }

            }
        }

        Box(modifier = Modifier.background(Color.Black).fillMaxHeight(0.90f)){
            content()
        }

        BottomAppBar (modifier = Modifier
            .fillMaxSize(),
            containerColor = colorNavBar
        ) {
            Row(modifier = Modifier
                .fillMaxSize(),
                horizontalArrangement = Arrangement.SpaceAround,
                verticalAlignment = Alignment.CenterVertically
            ) {

                ButtonIconPainterInt(painterResource(
                    if(onFavorite)R.drawable.favorite_button_full
                    else R.drawable.favorite_button_empty
                ),"Favorite",navControllerFavorite,index,onFavorite)

                ButtonIconPainterInt(painterResource(
                    if(onAccueil)R.drawable.home_button_full
                    else R.drawable.home_button_empty
                ),"Accueil",navControllerAccueil,index,onAccueil)

                ButtonIconPainterInt(painterResource(
                    if(onQuiz)R.drawable.quiz_button_full
                    else R.drawable.quiz_button_empty
                ),"Quiz",navControllerQuiz,index,onQuiz)

            }
        }
    }
}

@Composable
fun ButtonIconVectorInt(img : ImageVector, name : String, nav : (Int)->Unit ,index: Int,onPage : Boolean){
    IconButton(onClick = {nav(index)},
        enabled = !onPage,
        colors = IconButtonColors(Color.Transparent, colorButtonNav,//couleur quand il n'est pas selectionné
                                Color.Transparent, colorButtonNavSelected),//couleur quand il est selectionné
        modifier = Modifier
            .size(60.dp)
    ) {
        Icon(img,
            contentDescription = name,
            modifier = Modifier
                .fillMaxSize()
        )
    }
}


@Composable
fun ButtonIconPainterInt(img : Painter, name : String, nav : (Int)->Unit,index: Int,onPage : Boolean){
    IconButton(onClick = {nav(index)},
        enabled = !onPage,
        colors = IconButtonColors(Color.Transparent,colorButtonNav,//couleur quand il n'est pas selectionné
                                Color.Transparent, colorButtonNavSelected),//couleur quand il est selectionné
        modifier = Modifier
            .size(60.dp)
    ) {
        Icon(img,
            contentDescription = name,
            modifier = Modifier
                .fillMaxSize()
        )
    }
}

