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.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.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.vanpra.composematerialdialogs.MaterialDialogState

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

        colors = TextFieldDefaults.colors(
            unfocusedTextColor = Color.White,
            unfocusedPlaceholderColor = Grey,
            unfocusedContainerColor = Color.Transparent,
            focusedTextColor = Color.White,
            focusedContainerColor = Color.Transparent,
            focusedPlaceholderColor = Grey,
            focusedIndicatorColor = DarkPurple,
            unfocusedIndicatorColor = DarkPurple,
            errorContainerColor = Color.Transparent,
            errorTextColor = Color.White,
            errorPlaceholderColor = Grey,
        ),
        isError = flag,
        trailingIcon = {
            Icon(
                Icons.Filled.DateRange,
                contentDescription = "Дата рождения",
                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
        )
    )
}
