package com.example.mystictale.resources.components

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.text.KeyboardOptions
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.sp
import com.example.mystictale.ui.theme.DarkPurple
import com.example.mystictale.ui.theme.Grey
import com.example.mystictale.ui.theme.OpenSans

@Composable
fun GenericTextField(
    value: String,
    onValue: (String) -> Unit,
    placeholder: String,
    keyboardType: KeyboardType,
    flag: Boolean
) {
    TextField(
        value = value,
        onValueChange = onValue,
        Modifier
            .fillMaxWidth(),
        keyboardOptions = KeyboardOptions(
            keyboardType = keyboardType
        ),
        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,
        placeholder = { Text(text = placeholder) },
        maxLines = 1,
        textStyle = TextStyle(
            fontFamily = OpenSans,
            fontWeight = FontWeight.Light,
            fontSize = 15.sp
        )
    )
}