package com.example.mystictale.resources.components.dateComponents

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.DateRange
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.mystictale.ui.theme.DarkPurple
import com.example.mystictale.ui.theme.Grey
import com.example.mystictale.ui.theme.OpenSans
import com.example.mystictale.ui.theme.Purple
import com.vanpra.composematerialdialogs.MaterialDialogState

@Composable
fun DateOfBirthTextFieldForProfile(
    dateOfBirth: String,
    onValue: (String) -> Unit,
    dateDialogState: MaterialDialogState,
    flag: Boolean,
    enabled: Boolean
) {
    val padding = 10.dp;
    TextField(
        value = dateOfBirth,
        onValueChange = onValue,
        Modifier
            .fillMaxWidth()
            .clip(RoundedCornerShape(10.dp)),
        keyboardOptions = KeyboardOptions(
            keyboardType = KeyboardType.Number
        ),

        colors = TextFieldDefaults.colors(
            unfocusedTextColor = Color.White,
            unfocusedPlaceholderColor = Grey,
            unfocusedContainerColor = Purple,
            focusedTextColor = Color.White,
            focusedContainerColor = Purple,
            focusedPlaceholderColor = Color.White,
            focusedIndicatorColor = Color.Transparent,
            unfocusedIndicatorColor = Color.Transparent,
            errorContainerColor = Purple    ,
            errorTextColor = Color.White,
            errorIndicatorColor = Color.Transparent,
            errorPlaceholderColor = Color.White,
            disabledTextColor = Color.White,
            disabledContainerColor = DarkPurple,
            disabledPlaceholderColor = Color.White,
        ),
        isError = flag,
        enabled = enabled,
        trailingIcon = {
            Icon(
                Icons.Filled.DateRange,
                contentDescription = "Дата рождения",
                tint = if (enabled) {
                    Color.White
                } else {
                    DarkPurple
                },
                modifier = Modifier
                    .offset(x = -padding)
                    .padding(end = 2.dp)
                    .clickable { dateDialogState.show() }
            )
        },
        visualTransformation = dateOfBirthVisualTransformation(),
        placeholder = { Text("Дата рождения") },
        maxLines = 1,
        textStyle = TextStyle(
            fontFamily = OpenSans,
            fontWeight = FontWeight.Light,
            fontSize = 15.sp
        ),
    )
}
