package com.pixelized.biblib.ui.screen.authentication.composable

import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.AutofillType
import androidx.compose.ui.res.stringResource
import com.pixelized.biblib.R
import com.pixelized.biblib.utils.extention.autofill

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun LoginField(
    modifier: Modifier = Modifier,
    value: String,
    onValueChange: (String) -> Unit,
    keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
    keyboardActions: KeyboardActions = KeyboardActions(),
) {
    TextField(
        modifier = modifier.autofill(
            autofillTypes = listOf(AutofillType.Username, AutofillType.EmailAddress),
            onFill = onValueChange,
        ),
        value = value,
        onValueChange = onValueChange,
        label = { Text(text = stringResource(id = R.string.authentication_login)) },
        colors = TextFieldDefaults.outlinedTextFieldColors(),
        maxLines = 1,
        singleLine = true,
        keyboardOptions = keyboardOptions,
        keyboardActions = keyboardActions,
    )
}