package com.example.triphelper.view.style

import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.testirovanye_supabase.R
import com.example.triphelper.view.theme.Casagrand
import com.example.triphelper.view.theme.SeoulLight
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.focus.FocusManager

//Класс для
@Composable
fun TextFieldStyleAuth(text: String, mutableState: MutableState<String>, check: Boolean) {
    TextField(
        value = mutableState.value,
        onValueChange = { newText -> mutableState.value = newText },
        singleLine = true,
        placeholder = {
            Text(
                text = text,
                color = Color(0xFFDC5B6E).copy(alpha = 0.7f),
                fontSize = 24.sp,
                fontFamily = SeoulLight
            )
        },
        modifier = Modifier
            .height(70.dp)
            .fillMaxWidth()
            .border(
                width = 4.dp,
                color = Color(0xFF510B3C),
                shape = RoundedCornerShape(15.dp)
            ),
        shape = RoundedCornerShape(15.dp),
        colors = TextFieldDefaults.colors(
            cursorColor = Color(0xFFDC5B6E),
            focusedIndicatorColor = Color.Transparent,
            unfocusedIndicatorColor = Color.Transparent,
            focusedContainerColor = Color.White,
            unfocusedContainerColor = Color.White,
            unfocusedPlaceholderColor = Color(0xFF939396)
        ),
        keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text,
            imeAction = if (check) ImeAction.Next else ImeAction.Done),
        textStyle = TextStyle(
            color = Color(0xFFDC5B6E),
            fontSize = 25.sp,
            fontFamily = SeoulLight,
            fontWeight = FontWeight.W600
        )

    )
}


@Composable
fun TextFieldStylePasswordAuth(text: String, mutableState: MutableState<String>, check:Boolean) {
    var passwordVisibility by remember { mutableStateOf(false) }
    val focusManager = LocalFocusManager.current // Получаем менеджер фокуса
    TextField(
        value = mutableState.value,
        onValueChange = { newText -> mutableState.value = newText },
        singleLine = true,
        visualTransformation = if (passwordVisibility) VisualTransformation.None else PasswordVisualTransformation(
            '·'
        ),
        trailingIcon = {
            IconButton(
                onClick = { passwordVisibility = !passwordVisibility },
                modifier = Modifier.padding(end = 10.dp)
            ) {
                Icon(
                    painter = painterResource(id = if (passwordVisibility) R.drawable.eye_open else R.drawable.eye_close),
                    contentDescription = null,
                    tint = Color(0xFFDC5B6E).copy(alpha = 0.7f)
                )
            }
        },
        placeholder = {
            Text(
                text = text,
                color = Color(0xFFDC5B6E).copy(alpha = 0.7f),
                fontSize = 24.sp,
                fontFamily = SeoulLight
            )
        },
        modifier = Modifier
            .height(70.dp)
            .fillMaxWidth()
            .border(
                width = 4.dp,
                color = Color(0xFF510B3C),
                shape = RoundedCornerShape(15.dp)
            ),
        shape = RoundedCornerShape(15.dp),
        colors = TextFieldDefaults.colors(
            cursorColor = Color(0xFFDC5B6E),
            focusedIndicatorColor = Color.Transparent,
            unfocusedIndicatorColor = Color.Transparent,
            focusedContainerColor = Color.White,
            unfocusedContainerColor = Color.White,
            unfocusedPlaceholderColor = Color(0xFF939396)
        ),
        keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text,
            imeAction = if (check) ImeAction.Next else ImeAction.Done),
        textStyle = TextStyle(
            color = Color(0xFFDC5B6E),
            fontSize = 25.sp,
            fontFamily = SeoulLight,
            fontWeight = FontWeight.W600
        )

    )
}

@Composable
fun TripHelperLogoStyle() {
    Column(
        modifier = Modifier
            .padding(start = 20.dp)
            .fillMaxWidth(),
    ) {
        Image(
            painter = painterResource(id = R.drawable.logoth),
            contentDescription = null,
        )
        Box()
        {
            Text(
                text = "TRIP HELPER",
                fontFamily = Casagrand,
                fontSize = 40.sp,
                modifier = Modifier.padding(top = 15.dp),
                color = Color(0xFF510B3C)
            )
        }
    }
}
