package com.vpn.fastestvpnservice.screens

import android.content.res.Configuration
import android.graphics.fonts.Font
import android.graphics.fonts.FontStyle
import android.provider.CalendarContract.Colors
import android.text.Layout
import android.widget.Toast
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.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.material.icons.Icons
import androidx.compose.material.icons.filled.Lock
import androidx.compose.material.icons.filled.ThumbUp
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
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.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.LineHeightStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.UiMode
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.helpers.BasePreferenceHelper
import com.vpn.fastestvpnservice.sealedClass.Screen
import kotlinx.coroutines.delay

@Composable
fun Splash(navHostController: NavHostController) {
    val context = LocalContext.current
    val basePreferenceHelper = BasePreferenceHelper(context)

    Box(modifier = Modifier
        .paint(
            painter = painterResource(id = R.drawable.bg_img3),
            contentScale = ContentScale.FillBounds)
//        .background(if (isSystemInDarkTheme()) Color.Black
//        else colorResource(id = R.color.transparent))
        .fillMaxSize(),

    ) {
        Image(
            modifier = Modifier
                .width(146.dp)
                .height(199.dp)
                .align(Alignment.Center),
            painter = painterResource(
                id = R.drawable.fastestapp_logo3x),
            contentDescription = "FastestVPN",
            )
        Image(
            modifier = Modifier
                .align(Alignment.BottomCenter)
                .padding(bottom = 83.dp)
                .width(202.dp)
                .height(28.dp),
            painter = painterResource(
                id = R.drawable.fastestvpn_name3),
            contentDescription = "FastestVPN Name",
        )
        Row (
            modifier = Modifier
                .align(Alignment.BottomCenter)
                .padding(50.dp),
        ){

        }

    }

    val isLoggedIn = basePreferenceHelper.getLoggedInState()

    LaunchedEffect(key1 = true) {
        delay(3000)

        if (isLoggedIn) {
//            Toast.makeText(context, "if $isLoggedIn", Toast.LENGTH_SHORT).show()
            navHostController.popBackStack()
            navHostController.navigate(Screen.BottomBarMainScreen.route)
        } else {
//            Toast.makeText(context, "else $isLoggedIn", Toast.LENGTH_SHORT).show()
            navHostController.popBackStack()
            navHostController.navigate(Screen.Started.route)
        }

    }
}

@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
@Composable
fun SplashDarkThemePreview() {
    Splash(navHostController = rememberNavController())
}

@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
fun SplashDarkThemePreviewDark() {
    Splash(navHostController = rememberNavController())
}