package com.example.studybuddy.view.panels.bottombar

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.navigation.NavHostController
import com.example.testirovanye_supabase.R
import com.example.triphelper.view.navigation.NavigationRoutes
import com.example.triphelper.view.theme.SeoulBold

//Данная функция отвечает за отрисовку нижней части экрана - BottomAppBar
@Composable
fun BottomBar(controller: NavController,
              iconsLawIsActivity: MutableState<Boolean>, iconsProfileIsActivity: MutableState<Boolean>,
              iconsAdviceIsActivity: MutableState<Boolean>,iconsMainIsActivity: MutableState<Boolean>, iconsRoutsIsActivity: MutableState<Boolean>) {
    BottomAppBar(
        containerColor = Color.Transparent,
        modifier = Modifier
            .fillMaxWidth()
            .fillMaxHeight(0.2f)
    )
    {
        Box(
            Modifier
                .background(Color.Transparent)
                .fillMaxHeight(0.9f)
                .fillMaxWidth(),
            contentAlignment = Alignment.BottomCenter
        ) {
            Box(
                Modifier
                    .background(Color.White)
                    .fillMaxHeight(0.6f)
                    .border(
                        width = 3.dp,
                        color = Color(0xFFDC5B6E)
                    ),
                contentAlignment = Alignment.CenterStart
            ) {
                Row(
                    verticalAlignment = Alignment.CenterVertically,
                    modifier = Modifier.fillMaxWidth()
                ) {
                    Column(
                        modifier = Modifier
                            .weight(1.2f, true)
                            .padding(start = 10.dp)
                    ) {
                        IconButton(
                            onClick = {
                                controller.navigate(NavigationRoutes.MAIN)
                            },
                            modifier = Modifier
                                .size(55.dp)
                        ) {
                            Icon(
                                painter = painterResource(id = if(iconsMainIsActivity.value) R.drawable.mainscreen_active else R.drawable.mainscreen_not_active),
                                contentDescription = "Главный экран",
                                tint = Color.Unspecified,
                                modifier = Modifier.size(40.dp)
                            )
                        }
                        Text(
                            text = "Главная",
                            fontFamily = SeoulBold,
                            fontSize = 14.sp,
                            color = Color(0xFFDC5B6E),
                            modifier = Modifier.padding(start = 5.dp)
                        )
                    }
                    Column(
                        modifier = Modifier
                            .weight(1.9f, true)
                            .padding(end = 30.dp)
                    ) {
                        IconButton(
                            onClick = {
                                controller.navigate(NavigationRoutes.LAW)
                            },
                            modifier = Modifier
                                .size(50.dp)

                        ) {
                            Icon(
                                painter = painterResource(id = if(iconsLawIsActivity.value) R.drawable.lawscreen_active else R.drawable.lawscreen_not_active),
                                contentDescription = "Законы и правила",
                                tint = Color(0xFFDC5B6E),
                                modifier = Modifier.size(40.dp)
                            )
                        }
                        Text(
                            text = "Законы",
                            fontFamily = SeoulBold,
                            fontSize = 14.sp,
                            color = Color(0xFFDC5B6E),
                            modifier = Modifier.padding(start = 5.dp)
                        )
                    }
                    Column(
                        modifier = Modifier
                            .weight(1.4f, true)
                            .padding(start = 30.dp)
                    ) {
                        IconButton(
                            onClick = {
                            },
                            modifier = Modifier
                                .size(50.dp)

                        ) {
                            Icon(
                                painter = painterResource(id = if(iconsAdviceIsActivity.value) R.drawable.advicescreen_active else R.drawable.advicescreen_not_active),
                                contentDescription = "Советы и помощь",
                                tint = Color(0xFFDC5B6E),
                                modifier = Modifier.size(40.dp)
                            )
                        }
                        Text(
                            text = "Советы",
                            fontFamily = SeoulBold,
                            fontSize = 14.sp,
                            color = Color(0xFFDC5B6E),
                            modifier = Modifier.padding(start = 5.dp)
                        )
                    }
                    Column(
                        modifier = Modifier
                            .weight(0.9f, true)
                    ) {
                        IconButton(
                            onClick = {},
                            modifier = Modifier
                                .size(50.dp)
                        ) {
                            Icon(
                                painter = painterResource(id = if(iconsProfileIsActivity.value) R.drawable.profilescreen_active else R.drawable.profilescreen_not_active),
                                contentDescription = "Профиль",
                                tint = Color.Unspecified,
                                modifier = Modifier.size(40.dp),
                            )
                        }
                        Text(
                            text = "Профиль",
                            fontFamily = SeoulBold,
                            fontSize = 14.sp,
                            color = Color(0xFFDC5B6E)
                        )
                    }
                }
            }
            Box(
                modifier = Modifier.fillMaxHeight(),
                contentAlignment = Alignment.Center
            ) {
                if(iconsRoutsIsActivity.value){
                    IconButton(
                        onClick = {
                            controller.navigate((NavigationRoutes.CH_LOC))
                        },
                        modifier = Modifier
                            .size(111.dp)
                            .background(color = Color(0xFFDC5B6E), RoundedCornerShape(100.dp))
                            .border(
                                width = 5.dp,
                                color = Color(0xFF510B3C),
                                RoundedCornerShape(100.dp)
                            )
                    ) {
                        Icon(
                            painter = painterResource(id = R.drawable.route_not_active),
                            contentDescription = "Маршруты и туры",
                            tint = Color(0xFF510B3C),
                        )
                    }
                }
                else{
                    IconButton(
                        onClick = {
                            controller.navigate((NavigationRoutes.CH_LOC))
                        },
                        modifier = Modifier
                            .size(111.dp)
                            .background(color = Color(0xFFDC5B6E), RoundedCornerShape(100.dp))
                    ) {
                        Icon(
                            painter = painterResource(id = R.drawable.route_not_active),
                            contentDescription = "Маршруты и туры",
                            tint = Color.White,
                        )
                    }
                }
            }
        }
    }
}