1package com.peachpasswords.ui.vault23import androidx.compose.foundation.border4import androidx.compose.foundation.clickable5import androidx.compose.foundation.layout.Arrangement6import androidx.compose.foundation.layout.Box7import androidx.compose.foundation.layout.Column8import androidx.compose.foundation.layout.Row9import androidx.compose.foundation.layout.Spacer10import androidx.compose.foundation.layout.fillMaxWidth11import androidx.compose.foundation.layout.height12import androidx.compose.foundation.layout.padding13import androidx.compose.foundation.layout.width14import androidx.compose.foundation.shape.RoundedCornerShape15import androidx.compose.foundation.text.BasicTextField16import androidx.compose.material3.Text17import androidx.compose.runtime.Composable18import androidx.compose.ui.Alignment19import androidx.compose.ui.Modifier20import androidx.compose.ui.draw.clip21import androidx.compose.ui.graphics.SolidColor22import androidx.compose.ui.text.TextStyle23import androidx.compose.ui.text.input.KeyboardType24import androidx.compose.ui.text.input.PasswordVisualTransformation25import androidx.compose.foundation.text.KeyboardOptions26import androidx.compose.ui.unit.dp27import androidx.compose.ui.unit.sp28import com.peachpasswords.ui.theme.LocalPeachAccent29import com.peachpasswords.ui.theme.PeachColors30import com.peachpasswords.ui.theme.PeachType31323334353637383940414243@Composable44fun CardEditFields(45 cardNumber: String,46 cardholderName: String,47 expiry: String,48 cvc: String,49 showCvc: Boolean,50 network: String,51 onCardNumber: (String) -> Unit,52 onCardholder: (String) -> Unit,53 onExpiry: (String) -> Unit,54 onCvc: (String) -> Unit,55 onToggleShowCvc: () -> Unit,56) {57 58 CardField(59 label = "card number",60 value = cardNumber,61 onChange = { raw -> onCardNumber(CardFieldUtils.formatPan(raw)) },62 keyboardType = KeyboardType.Number,63 labelTrailing = {64 val net = CardFieldUtils.networkLabel(network)65 if (net.isNotEmpty()) {66 Text(net, color = PeachColors.T2, fontFamily = PeachType.Mono, fontSize = 9.sp)67 }68 },69 )7071 72 CardField(73 label = "cardholder",74 value = cardholderName,75 onChange = onCardholder,76 mono = false,77 )7879 80 CardField(81 label = "expiry",82 value = expiry,83 onChange = { raw -> onExpiry(CardFieldUtils.formatExpiry(raw)) },84 keyboardType = KeyboardType.Number,85 )8687 88 val cvcMax = CardFieldUtils.cvcMaxDigits(network)89 CardField(90 label = "cvc",91 value = cvc,92 onChange = { raw -> onCvc(raw.filter { it.isDigit() }.take(cvcMax)) },93 keyboardType = KeyboardType.NumberPassword,94 masked = !showCvc,95 trailing = {96 Text(97 if (showCvc) "hide" else "show",98 color = LocalPeachAccent.current, fontFamily = PeachType.Mono, fontSize = 9.sp,99 modifier = Modifier.clip(RoundedCornerShape(6.dp)).clickable(onClick = onToggleShowCvc).padding(6.dp),100 )101 },102 )103}104105106107108109110111@Composable112private fun CardField(113 label: String,114 value: String,115 onChange: (String) -> Unit,116 mono: Boolean = true,117 masked: Boolean = false,118 keyboardType: KeyboardType = KeyboardType.Text,119 labelTrailing: (@Composable () -> Unit)? = null,120 trailing: (@Composable () -> Unit)? = null,121) {122 val accent = LocalPeachAccent.current123 Column(Modifier.fillMaxWidth().padding(bottom = 14.dp)) {124 Row(verticalAlignment = Alignment.CenterVertically) {125 Text(label.uppercase(), color = PeachColors.T1, fontFamily = PeachType.Mono, fontSize = 8.sp)126 if (labelTrailing != null) {127 Spacer(Modifier.width(8.dp))128 labelTrailing()129 }130 }131 Spacer(Modifier.height(6.dp))132 Row(verticalAlignment = Alignment.CenterVertically) {133 Box(134 Modifier.weight(1f)135 .border(1.dp, PeachColors.T3, RoundedCornerShape(10.dp))136 .padding(horizontal = 12.dp, vertical = 12.dp),137 ) {138 BasicTextField(139 value = value,140 onValueChange = onChange,141 singleLine = true,142 textStyle = TextStyle(143 color = PeachColors.T0,144 fontFamily = if (mono) PeachType.Mono else PeachType.Body,145 fontSize = 13.sp,146 ),147 cursorBrush = SolidColor(accent),148 keyboardOptions = KeyboardOptions(keyboardType = keyboardType),149 visualTransformation = if (masked) PasswordVisualTransformation() else androidx.compose.ui.text.input.VisualTransformation.None,150 modifier = Modifier.fillMaxWidth(),151 )152 }153 if (trailing != null) { Spacer(Modifier.width(8.dp)); trailing() }154 }155 }156}