package com.peachpasswords.ui.vault import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box 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.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.BasicTextField import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip 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.PasswordVisualTransformation import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.peachpasswords.ui.theme.LocalPeachAccent import com.peachpasswords.ui.theme.peachColors import com.peachpasswords.ui.theme.PeachType /** * D2 — EntryEdit CARD field block. Self-contained: drop a single call to * [CardEditFields] in place of the login fields when `f.type == "card"`. * * Mirrors the existing private `Field` underline style in EntryEditScreen.kt * (1.dp T3 border, mono 13sp, accent cursor). Includes its own label+box * primitive (`CardField`) so it does not depend on that file's private members. * * Network is detected live from the card number; CVC maxLength + PAN grouping * follow the detected network (Amex 15/4, others 16/3). */ @Composable fun CardEditFields( cardNumber: String, cardholderName: String, expiry: String, cvc: String, showCvc: Boolean, network: String, onCardNumber: (String) -> Unit, onCardholder: (String) -> Unit, onExpiry: (String) -> Unit, onCvc: (String) -> Unit, onToggleShowCvc: () -> Unit, ) { // CARD NUMBER — auto-formatted, network label beside the label. CardField( label = "card number", value = cardNumber, onChange = { raw -> onCardNumber(CardFieldUtils.formatPan(raw)) }, keyboardType = KeyboardType.Number, labelTrailing = { val net = CardFieldUtils.networkLabel(network) if (net.isNotEmpty()) { Text(net, color = peachColors.T2, fontFamily = PeachType.Mono, fontSize = 9.sp) } }, ) // CARDHOLDER — Inter body, not mono. CardField( label = "cardholder", value = cardholderName, onChange = onCardholder, mono = false, ) // EXPIRY — auto "MM/YY". CardField( label = "expiry", value = expiry, onChange = { raw -> onExpiry(CardFieldUtils.formatExpiry(raw)) }, keyboardType = KeyboardType.Number, ) // CVC — masked by default, eye toggle, maxLength by network. val cvcMax = CardFieldUtils.cvcMaxDigits(network) CardField( label = "cvc", value = cvc, onChange = { raw -> onCvc(raw.filter { it.isDigit() }.take(cvcMax)) }, keyboardType = KeyboardType.NumberPassword, masked = !showCvc, trailing = { Text( if (showCvc) "hide" else "show", color = LocalPeachAccent.current, fontFamily = PeachType.Mono, fontSize = 9.sp, modifier = Modifier.clip(RoundedCornerShape(6.dp)).clickable(onClick = onToggleShowCvc).padding(6.dp), ) }, ) } /** * Underline-style field matching EntryEditScreen's private `Field`. Duplicated * here (rather than reused) so this draft is a self-contained drop-in; the * orchestrator may instead route these through the existing `Field`/`PasswordField` * — see INTEGRATION.md for the cheaper wiring option. */ @Composable private fun CardField( label: String, value: String, onChange: (String) -> Unit, mono: Boolean = true, masked: Boolean = false, keyboardType: KeyboardType = KeyboardType.Text, labelTrailing: (@Composable () -> Unit)? = null, trailing: (@Composable () -> Unit)? = null, ) { val accent = LocalPeachAccent.current Column(Modifier.fillMaxWidth().padding(bottom = 14.dp)) { Row(verticalAlignment = Alignment.CenterVertically) { Text(label.uppercase(), color = peachColors.T1, fontFamily = PeachType.Mono, fontSize = 8.sp) if (labelTrailing != null) { Spacer(Modifier.width(8.dp)) labelTrailing() } } Spacer(Modifier.height(6.dp)) Row(verticalAlignment = Alignment.CenterVertically) { Box( Modifier.weight(1f) .border(1.dp, peachColors.T3, RoundedCornerShape(10.dp)) .padding(horizontal = 12.dp, vertical = 12.dp), ) { BasicTextField( value = value, onValueChange = onChange, singleLine = true, textStyle = TextStyle( color = peachColors.T0, fontFamily = if (mono) PeachType.Mono else PeachType.Body, fontSize = 13.sp, ), cursorBrush = SolidColor(accent), keyboardOptions = KeyboardOptions(keyboardType = keyboardType), visualTransformation = if (masked) PasswordVisualTransformation() else androidx.compose.ui.text.input.VisualTransformation.None, modifier = Modifier.fillMaxWidth(), ) } if (trailing != null) { Spacer(Modifier.width(8.dp)); trailing() } } } }