package com.example.triphelper.view.LawScreen

import android.media.audiofx.AudioEffect.Descriptor
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
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.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import coil.compose.AsyncImagePainter
import coil.compose.rememberAsyncImagePainter
import coil.request.ImageRequest
import com.example.triphelper.view.MainScreen.LawScreenViewModel
import com.example.triphelper.view.style.StyleMainFone
import com.example.triphelper.view.theme.Roboto
import com.example.triphelper.view.theme.RobotoB
import com.example.triphelper.view.theme.SeoulBold

@Composable
fun DescriptionLaws(navController: NavController, iconsLawIsActivity: MutableState<Boolean>,titleCountry:String, viewModel: LawScreenViewModel = hiltViewModel()) {
    iconsLawIsActivity.value = true
    val rules by viewModel.ruleses.collectAsState(initial = emptyList())

    LaunchedEffect(key1 = viewModel.navigationTo) {
        viewModel.navigationTo.collect { destination ->
            destination?.let {
                navController.navigate(destination)
            }
        }
    }
    Column(
        modifier = Modifier
            .fillMaxSize()
            .background(Color.White),
        verticalArrangement = Arrangement.Top,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        Column {
            Text(
                text = titleCountry,
                color = Color(0xFF510B3C),
                fontSize = 35.sp,
                fontFamily = SeoulBold,
                fontWeight = FontWeight.Bold,
                textAlign = TextAlign.Center,
                modifier = Modifier.padding(top = 60.dp)
            )
        }
        LaunchedEffect(Unit) {
            viewModel.GetRules(titleCountry)
        }
        LazyColumn(
            modifier = Modifier
                .padding(top = 20.dp,bottom = 60.dp)
                .fillMaxHeight(0.94f)
        ) {
            items(
                rules,
                key = { rules -> rules.id },
            ) { rules ->
                Column(
                    modifier = Modifier
                        .fillMaxWidth() ,
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement = Arrangement.spacedBy(20.dp)
                ) {
                    Text(
                        text = "Законы",
                        color = Color(0xFF510B3C),
                        fontSize = 26.sp,
                        fontFamily = SeoulBold,
                        fontWeight = FontWeight.Bold,
                        textAlign = TextAlign.Center
                    )
                    Text(
                        text = rules.laws,
                        color = Color(0xFF000000),
                        fontSize = 20.sp,
                        fontFamily = Roboto,
                        textAlign = TextAlign.Start,
                        modifier = Modifier.fillMaxWidth(0.9f)
                    )
                    Text(
                        text = "Правила культуры",
                        color = Color(0xFF510B3C),
                        fontSize = 26.sp,
                        fontFamily = SeoulBold,
                        fontWeight = FontWeight.Bold,
                        textAlign = TextAlign.Center
                    )
                    Text(
                        text = rules.rules_of_culture,
                        color = Color(0xFF000000),
                        fontSize = 20.sp,
                        fontFamily = Roboto,
                        textAlign = TextAlign.Start,
                        modifier = Modifier.fillMaxWidth(0.9f)
                    )
                    Text(
                        text = "Жесты",
                        color = Color(0xFF510B3C),
                        fontSize = 26.sp,
                        fontFamily = SeoulBold,
                        fontWeight = FontWeight.Bold,
                        textAlign = TextAlign.Center
                    )
                    Text(
                        text = rules.gestures,
                        color = Color(0xFF000000),
                        fontSize = 20.sp,
                        fontFamily = Roboto,
                        textAlign = TextAlign.Start,
                        modifier = Modifier.fillMaxWidth(0.9f).padding(bottom = 40.dp)
                    )
                }
            }

        }
    }
}