package com.vpn.fastestvpnservice.screens.bottomNavBarScreens

import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
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.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.Help
import androidx.compose.material.icons.filled.ElectricBolt
import androidx.compose.material.icons.filled.Email
import androidx.compose.material.icons.filled.EnergySavingsLeaf
import androidx.compose.material.icons.filled.Help
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.PrivacyTip
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.vpn.fastestvpnservice.R
import com.vpn.fastestvpnservice.sealedClass.Screen

@Composable
fun Help(navHostController: NavHostController) {
    Box(modifier = Modifier
        .background(MaterialTheme.colorScheme.background)
        .fillMaxSize(),
//        contentAlignment = Alignment.Center

    ) {
        Column(
            verticalArrangement = Arrangement.Top,
            horizontalAlignment = Alignment.Start,
            modifier = Modifier
                .padding(start = 16.dp, end = 24.dp)
                .fillMaxSize()
        ) {
            Spacer(modifier = Modifier.height(60.dp))
            AddTextHelp(
                text = "Help",
                size = 28.sp,
                color = MaterialTheme.colorScheme.primary
            )
            AddRow(icon = R.drawable.faq3x,
                text = "FAQ", navHostController = navHostController)
            {
                navHostController.navigate(
                Screen.FAQ.route
            )}
            AddRow(icon = R.drawable.privacy3x,
                text = "Privacy Policy", navHostController = navHostController) {
                navHostController.navigate(
                    Screen.PrivacyPolicy.route
                )
            }
            AddRow(icon = R.drawable.terms3x,
                text = "Terms and Conditions", navHostController = navHostController) {
                navHostController.navigate(
                    Screen.TermsAndConditions.route
                )
            }
            AddRow(icon = R.drawable.about3x,
                text = "About Fastest VPN", navHostController = navHostController) {
                navHostController.navigate(
                    Screen.About.route
                )
            }
            AddRow(icon = R.drawable.customer_support3x,
                text = "Customer Support",
                navHostController = navHostController) {
                navHostController.navigate(
                    Screen.CustomerSupport.route
                )
            }
        }
    }
}

@Composable
fun ColumnScope.AddRow(
    icon: Int,
    text: String,
    navHostController: NavHostController,
    onClick: () -> Unit
) {
    Row(
        modifier = Modifier
            .fillMaxWidth()
            .padding(top = 33.dp)
            .background(Color.Transparent)
            .height(30.dp)
            .pointerInput(Unit) {
                detectTapGestures {
                    Log.d("test_row", "Clicked Row ${onClick().toString()}")
                    onClick()
                }
            }
//            .clickable {
//                Log.d("test_row", "Clicked Row ${onClick.toString()}")
//                onClick()
//            }
                ,
        horizontalArrangement = Arrangement.Start,
        verticalAlignment = Alignment.CenterVertically
    ) {

        Surface(
            modifier = Modifier.padding(start = 0.dp),
            color = Color.Transparent
        ) {
            Image(
                painter = painterResource(id = icon),
                contentDescription = "World",
                modifier = Modifier
                    .padding(start = 0.dp)
                    .size(24.dp)
                    .weight(1f),
                colorFilter = ColorFilter.tint(
                    MaterialTheme.colorScheme.primary)
            )
        }

        Surface(
            modifier = Modifier.padding(start = 0.dp),
            color = Color.Transparent
        ) {
            Text(text = text,
                style = TextStyle(
                    color = MaterialTheme.colorScheme.primary,
                    fontSize = 16.sp,
                    fontStyle = FontStyle.Normal,
                    fontWeight = FontWeight.Medium
                ),
                maxLines = 2,
                modifier = Modifier
                    .padding(start = 20.dp, end = 0.dp)
                    .weight(1f)
            )
        }
        Spacer(modifier = Modifier.weight(1f))

        Surface(
            modifier = Modifier
                .padding(start = 15.dp)
                .align(Alignment.CenterVertically),
            color = Color.Transparent

        ) {
            Image(
                painter = painterResource(
                    id = R.drawable.frontarrow3x),
                contentDescription = "Front_Arrow",
                modifier = Modifier
                    .padding(start = 0.dp, end = 5.dp)
                    .size(10.dp, 18.dp)
                    .weight(1f)
                    .alpha(1F),
                colorFilter = ColorFilter.tint(
                    MaterialTheme.colorScheme.primary)
            )
        }


    }
}

@Composable
fun ColumnScope.AddTextHelp(text: String, size: TextUnit, color: Color) {
    Text(
        text = text,
        style = TextStyle(
            fontSize = size,
            color = color,
            textAlign = TextAlign.Center,
            fontStyle = FontStyle.Normal,
            fontWeight = FontWeight.Medium,
        ),
    )
}

@Preview
@Composable
fun HelpPreview() {
    Help(rememberNavController())
}
