package com.vpn.fastestvpnservice.screens

import android.content.res.Configuration
import android.util.Log
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
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.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Scaffold
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.paint
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.UiMode
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 Started(navHostController: NavHostController) {
    val configuration = LocalConfiguration.current
    val screenHeight = configuration.screenHeightDp.dp
    val screenWidth = configuration.screenWidthDp.dp

    Box (
        modifier = Modifier
            .fillMaxSize()
            .paint(
                painter = painterResource(id = R.drawable.bg_img3),
                contentScale = ContentScale.FillBounds)
//            .background(
//                if (isSystemInDarkTheme()) Color.Black
//                else Color.Transparent
//            )
        ,
        contentAlignment = Alignment.BottomCenter
        ) {
        Column (
            verticalArrangement = Arrangement.Bottom,
            horizontalAlignment = Alignment.CenterHorizontally,

            modifier = Modifier
                .fillMaxSize()
                .background(Color.Transparent),
        ) {

            Column (
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally,
                modifier = Modifier.padding(bottom = 25.dp)
            ) {
                Text(
                    modifier = Modifier
                        .padding(bottom = 25.dp),
                    fontSize = 30.sp,
                    fontWeight = FontWeight.SemiBold,
                    text = "Secure. Fast. Stable.",
                    color = colorResource(id = R.color.white),
                )
                Text(
                    modifier = Modifier
                        .padding(start = 0.dp),
                    fontSize = 14.sp,
                    fontWeight = FontWeight.Normal,
                    text = "Top-notch security, blazing speed,",
                    color = colorResource(id = R.color.light_grey),
                )
                Text(
                    modifier = Modifier
                        .padding(start = 0.dp),
                    fontSize = 14.sp,
                    fontWeight = FontWeight.Normal,
                    text = "Unwavering stability. Your digital world,",
                    color = colorResource(id = R.color.light_grey),
                )
                Text(
                    modifier = Modifier
                        .padding(start = 0.dp),
                    fontSize = 14.sp,
                    fontWeight = FontWeight.Normal,
                    text = "Protected.",
                    color = colorResource(id = R.color.light_grey),
                )
            }

            Row (
                modifier = Modifier
                    .padding(bottom = 50.dp),
                horizontalArrangement = Arrangement.Center,
                verticalAlignment = Alignment.Bottom

            ) {
                Button(
                    onClick = {
                        Log.d("test_button", "onClick Send Code")
                        navHostController.popBackStack()
                        navHostController.navigate(Screen.Login.route)
                    },
                    modifier = Modifier
                        .padding(
                            start = 15.dp, end = 5.dp,
                            bottom = 15.dp, top = 15.dp
                        )
                        .background(colorResource(id = R.color.transparent))
                        .weight(1F)
                        .height(60.dp),

                    shape = RoundedCornerShape(15.dp),
                    colors = ButtonDefaults.buttonColors(
                        contentColor = colorResource(id = R.color.light_blue),
                        containerColor = colorResource(id = R.color.white),
                    ),
                )
                {
                    Text(text = "Sign In", fontSize = 20.sp)
                    Log.d("test_button", "RowScope")
                }

                Button(
                    onClick = {
                        Log.d("test_button", "onClick Send Code")
                        navHostController.popBackStack()
                        navHostController.navigate(Screen.SignUp.route)
                        },
                    modifier = Modifier
                        .padding(
                            start = 5.dp, end = 15.dp,
                            bottom = 15.dp, top = 15.dp
                        )
                        .background(colorResource(id = R.color.transparent))
                        .weight(1F)
                        .height(60.dp),

                    shape = RoundedCornerShape(15.dp),
                    colors = ButtonDefaults.buttonColors(
                        contentColor = colorResource(id = R.color.white),
                        containerColor = colorResource(id = R.color.transparent),
                    ),
                    border = BorderStroke(2.dp,
                        colorResource(id = R.color.white))
                )
                {
                    Text(text = "Sign Up", fontSize = 20.sp)
                    Log.d("test_button", "RowScope")
                }
            }
        }
    }

    Image(
        painter = painterResource(id = R.drawable.map2),
        contentDescription = "FastestVPN Map",
        modifier = Modifier
            .background(Color.Transparent)
            .height(screenHeight)
            .padding(top = 50.dp)
            .width(screenWidth)
        ,
        alignment = Alignment.TopCenter
    )
    Image(
        painter = painterResource(id = R.drawable.lines_fvpn3x),
        contentDescription = "FastestVPN Lines",
        modifier = Modifier
            .background(Color.Transparent)
            .width(screenWidth)
            .height(screenHeight)
            .padding(top = 123.dp, start = 27.dp,
                end = 27.dp)
        ,
        alignment = Alignment.TopCenter
    )

}

@Preview
@Composable
fun StartedPreview() {
    Started(rememberNavController())
}

@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
fun StartedPreviewDark() {
    Started(rememberNavController())
}