package com.example.development.domain.utils

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Icon
import androidx.compose.material3.IconToggleButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
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.development.R

@Composable
fun CustomPassword(
    text: String,
    search: String,
    onValueChange: (String) -> Unit

) {
    val password = remember { mutableStateOf("") }
    val flag = remember { mutableStateOf(false) }
    val checked = remember { mutableStateOf(false) }
    Box(
        modifier = Modifier
            .clip(RoundedCornerShape(10.dp))
            .background(Color(0XFFE8EFFF))
            .width(300.dp)
            .height(50.dp)
    ) {
        OutlinedTextField(
            keyboardOptions = KeyboardOptions(
                keyboardType = KeyboardType.Password
            ),
            trailingIcon = {
                IconToggleButton(
                    checked = checked.value,
                    onCheckedChange = { checked.value = it }) {
                    Icon(
                        if (checked.value) {
                            painterResource(id = R.drawable.eye_open)
                        } else {
                            painterResource(id = R.drawable.eye_close)
                        },
                        contentDescription = "Скрыть пароль",
                        tint = Color(0XFF939396),
                        modifier = Modifier.width(20.dp)
                    )
                }
            },
            visualTransformation = if (checked.value) VisualTransformation.None else PasswordVisualTransformation(),
            value = search,
            onValueChange = onValueChange,
            textStyle = TextStyle(
                color = Color.Black,
                fontSize = 15.sp
            ),
            colors = TextFieldDefaults.colors(
                focusedContainerColor  = Color(0XFFF5F5F9),
                focusedIndicatorColor = Color(0xFFEBEBEB),
                focusedTextColor = Color(0XFF578FFF),
                disabledIndicatorColor = Color.White,
                unfocusedIndicatorColor = Color.White,
                cursorColor = Color(0XFF578FFF),
                focusedSupportingTextColor = Color(0xFF00000)
            ),
            modifier = Modifier
                .fillMaxWidth(1f)
                .background(Color(0XFFF5F5F9))
                .height(height = 50.dp)
                .width(width = 200.dp),
            placeholder = {
                Text(
                    modifier = Modifier.fillMaxWidth(),
                    text = text,
                    fontSize = 15.sp,
                    color = Color(0XFF939396)
                )
            }
        )
    }
}