package com.peachpasswords.ui.components import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.collectIsFocusedAsState import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.drawBehind import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.em import androidx.compose.ui.unit.sp import com.peachpasswords.ui.theme.LocalPeachAccent import com.peachpasswords.ui.theme.PeachSpacing import com.peachpasswords.ui.theme.PeachType import com.peachpasswords.ui.theme.peachColors @Composable fun PeachField( label: String, value: String, onValueChange: (String) -> Unit, modifier: Modifier = Modifier, singleLine: Boolean = true, mono: Boolean = true, keyboardType: KeyboardType = KeyboardType.Text, visualTransformation: VisualTransformation = VisualTransformation.None, trailing: (@Composable () -> Unit)? = null, ) { val accent = LocalPeachAccent.current val interaction = remember { MutableInteractionSource() } val focused by interaction.collectIsFocusedAsState() val hairline = peachColors.T3 Column(modifier.fillMaxWidth()) { Text( label.uppercase(), color = peachColors.T2, fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.08.em, ) Row(verticalAlignment = Alignment.CenterVertically) { BasicTextField( value = value, onValueChange = onValueChange, singleLine = singleLine, textStyle = TextStyle( color = peachColors.T0, fontFamily = if (mono) PeachType.Mono else PeachType.Body, fontSize = 13.sp, ), cursorBrush = SolidColor(accent), interactionSource = interaction, keyboardOptions = KeyboardOptions(keyboardType = keyboardType), visualTransformation = visualTransformation, modifier = Modifier .weight(1f) .drawBehind { drawRect( color = if (focused) accent else hairline, topLeft = Offset(0f, size.height - 1.dp.toPx()), size = Size(size.width, 1.dp.toPx()), ) } .padding(vertical = PeachSpacing.sm), ) if (trailing != null) { Spacer(Modifier.width(PeachSpacing.sm)) trailing() } } } }