package com.peachpasswords.ui.settings import android.content.Intent import android.net.Uri import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.core.animateDpAsState import androidx.compose.foundation.background 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.FlowRow import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.RowScope 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.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.BasicTextField import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.em import androidx.compose.ui.unit.sp import androidx.compose.material3.Text import com.peachpasswords.ui.PeachNav import com.peachpasswords.ui.theme.ACCENT_COLORS import com.peachpasswords.ui.theme.PeachType import com.peachpasswords.vault.VaultSettings import kotlinx.coroutines.launch private const val PRO_URL = "https://buy.polar.sh/polar_cl_IXSFIPojx67rcOTksn8LkH5mnU3osPHtYqBIl1eyuIz" /** * Body content for the active stack card. Everything is tinted with the card's * own foreground [fg] (the browser's `currentColor` convention), so each card's * rows inherit its palette. Rows whose backend doesn't exist yet (duress, * canary, license activation) render their browser visual but defer the action * to a later phase — noted inline where that's the case. */ @Composable fun CardBody( id: CardId, fg: Color, vm: SettingsViewModel, settings: VaultSettings, entriesCount: Int, onNavigate: (PeachNav) -> Unit, ) { when (id) { CardId.Appearance -> AppearanceBody(fg, vm, settings) CardId.Protection -> ProtectionBody(fg, vm, settings, onNavigate) CardId.Vault -> VaultBody(fg, vm, settings, entriesCount, onNavigate) CardId.Sync -> SyncBody(fg, onNavigate) CardId.Shortcuts -> ShortcutsBody(fg) CardId.Pro -> ProBody(fg) CardId.Feedback -> FeedbackBody(fg) } } /* ───────────────────────── shared row vocabulary ───────────────────────── */ @Composable private fun SubLabel(text: String, fg: Color, top: Dp = 14.dp) { Text( text, modifier = Modifier.padding(top = top, bottom = 4.dp), color = fg.copy(alpha = 0.58f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em, ) } @Composable private fun RowLine(fg: Color, content: @Composable RowScope.() -> Unit) { Row( Modifier.fillMaxWidth().padding(vertical = 9.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, content = content, ) Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.12f))) } @Composable private fun RowScope.Name(text: String, fg: Color) { Text(text, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp, modifier = Modifier.weight(1f)) } @Composable private fun ValueText(text: String, fg: Color) { Text(text, color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Mono, fontSize = 11.sp) } @Composable private fun SubtleButton(label: String, fg: Color, onClick: () -> Unit) { Box( Modifier.clip(RoundedCornerShape(8.dp)) .border(1.dp, fg.copy(alpha = 0.28f), RoundedCornerShape(8.dp)) .background(fg.copy(alpha = 0.08f)) .clickable(onClick = onClick) .padding(horizontal = 12.dp, vertical = 6.dp), ) { Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp) } } @Composable private fun Toggle(on: Boolean, fg: Color, onToggle: (Boolean) -> Unit) { val knob by animateDpAsState(if (on) 16.dp else 2.dp, label = "knob") Box( Modifier.size(width = 34.dp, height = 20.dp).clip(RoundedCornerShape(999.dp)) .background(if (on) fg.copy(alpha = 0.28f) else fg.copy(alpha = 0.08f)) .border(1.dp, fg.copy(alpha = if (on) 0.5f else 0.32f), RoundedCornerShape(999.dp)) .clickable { onToggle(!on) }, ) { Box( Modifier.padding(top = 2.dp).width(16.dp).fillMaxWidth().height(16.dp) .padding(start = knob - 2.dp) .size(14.dp).clip(CircleShape) .background(if (on) fg else fg.copy(alpha = 0.58f)), ) } } @Composable private fun Pill(label: String, active: Boolean, fg: Color, onClick: () -> Unit) { Box( Modifier.clip(RoundedCornerShape(999.dp)) .border(1.dp, fg.copy(alpha = if (active) 0.55f else 0.32f), RoundedCornerShape(999.dp)) .background(if (active) fg.copy(alpha = 0.18f) else Color.Transparent) .clickable(onClick = onClick) .padding(horizontal = 12.dp, vertical = 5.dp), ) { Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp) } } @Composable private fun ProBadge(fg: Color) { Box( Modifier.padding(start = 6.dp).clip(RoundedCornerShape(4.dp)) .background(fg.copy(alpha = 0.16f)).padding(horizontal = 5.dp, vertical = 1.dp), ) { Text("Pro", color = fg.copy(alpha = 0.85f), fontFamily = PeachType.Mono, fontSize = 8.sp) } } @Composable private fun Hint(text: String, fg: Color) { Text( text, modifier = Modifier.padding(top = 6.dp), color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.5.sp, lineHeight = 16.sp, ) } /* ────────────────────────────── Appearance ─────────────────────────────── */ @OptIn(ExperimentalLayoutApi::class) @Composable private fun AppearanceBody(fg: Color, vm: SettingsViewModel, s: VaultSettings) { SubLabel("THEME", fg, top = 0.dp) RowLine(fg) { Name("Theme", fg) SubtleButton(if (s.theme == "dark") "Switch to light" else "Switch to dark", fg) { vm.setTheme(if (s.theme == "dark") "light" else "dark") } } SubLabel("ACCENT", fg) FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { ACCENT_COLORS.forEach { (name, color) -> Box( Modifier.size(22.dp).clip(CircleShape).background(color) .border( if (s.accentColor == name) 2.dp else 1.dp, if (s.accentColor == name) fg else fg.copy(alpha = 0.2f), CircleShape, ) .clickable { vm.setAccent(name) }, ) } } SubLabel("TEXT SIZE", fg) RowLine(fg) { Name("Size", fg) Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) { Pill("Default", s.textSize == "medium", fg) { vm.setTextSize("medium") } Pill("Large", s.textSize == "large", fg) { vm.setTextSize("large") } } } SubLabel("MOTION", fg) RowLine(fg) { Name("Reduce motion", fg) SubtleButton(if (s.reduceMotion) "On" else "Off", fg) { vm.setReduceMotion(!s.reduceMotion) } } } /* ────────────────────────────── Protection ─────────────────────────────── */ @Composable private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) { val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never") val current = s.autoLockMinutes ?: 0 SubLabel("LOCKING", fg, top = 0.dp) RowLine(fg) { Name("Auto-lock after", fg) val idx = lockOptions.indexOfFirst { it.first == current }.coerceAtLeast(0) SubtleButton(lockOptions[idx].second, fg) { val next = lockOptions[(idx + 1) % lockOptions.size].first vm.setAutoLockMinutes(if (next == 0) 0 else next) } } SubLabel("BIOMETRICS", fg) RowLine(fg) { Name("Unlock with biometrics", fg) Toggle(s.biometricsEnabled, fg) { vm.setBiometrics(it) } } SubLabel("RECOVERY", fg) RowLine(fg) { Name("View recovery words", fg) SubtleButton("view", fg) { onNavigate(PeachNav.RecoveryView) } } SubLabel("BREACH PROTECTION", fg) RowLine(fg) { Name("Breach monitoring", fg) Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) } } SubLabel("MASTER PASSWORD", fg) ChangePasswordRow(fg, vm) SubLabel("DURESS PASSWORD", fg) RowLine(fg) { Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Duress password", fg); ProBadge(fg) } ValueText("off", fg) } Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Arrives with Pro sync.", fg) } @Composable private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) { var open by remember { mutableStateOf(false) } var current by remember { mutableStateOf("") } var next by remember { mutableStateOf("") } var confirm by remember { mutableStateOf("") } var error by remember { mutableStateOf(null) } var done by remember { mutableStateOf(false) } val scope = rememberCoroutineScope() RowLine(fg) { Name("Master password", fg) SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false } } AnimatedVisibility(open) { Column(Modifier.fillMaxWidth().padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) { PwField("current password", current, fg) { current = it } PwField("new password (min 12 chars)", next, fg) { next = it } PwField("confirm new password", confirm, fg) { confirm = it } error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) } if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp) SubtleButton("save new password", fg) { error = when { current.isBlank() -> "enter your current password" next.length < 12 -> "new password must be at least 12 characters" next != confirm -> "new passwords do not match" next == current -> "new password must differ from current" else -> null } if (error == null) scope.launch { if (vm.changePassword(current, next)) { current = ""; next = ""; confirm = ""; open = false; done = true } else error = "incorrect current password" } } } } } @Composable private fun PwField(placeholder: String, value: String, fg: Color, onChange: (String) -> Unit) { Box( Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)) .background(Color(0x2E000000)) .border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp)) .padding(horizontal = 10.dp, vertical = 10.dp), ) { if (value.isEmpty()) { Text(placeholder, color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Mono, fontSize = 12.sp) } BasicTextField( value = value, onValueChange = onChange, singleLine = true, textStyle = TextStyle(color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp), cursorBrush = SolidColor(fg), visualTransformation = PasswordVisualTransformation(), modifier = Modifier.fillMaxWidth(), ) } } /* ──────────────────────────────── Vault ───────────────────────────────── */ @Composable private fun VaultBody( fg: Color, vm: SettingsViewModel, s: VaultSettings, entriesCount: Int, onNavigate: (PeachNav) -> Unit, ) { val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never") val current = s.trashRetentionDays ?: 0 SubLabel("ENTRIES", fg, top = 0.dp) RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) } SubLabel("MAINTENANCE", fg) RowLine(fg) { Name("Trash auto-delete", fg) val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0) SubtleButton(trashOptions[idx].second, fg) { vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first) } } RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } } RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } } SubLabel("DATA", fg) RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } } RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } } RowLine(fg) { Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); ProBadge(fg) } SubtleButton("open", fg) { onNavigate(PeachNav.CodexGenerate) } } RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } } var advancedOpen by remember { mutableStateOf(false) } SubLabel("ADVANCED", fg) RowLine(fg) { Name("Advanced", fg) SubtleButton(if (advancedOpen) "hide" else "show", fg) { advancedOpen = !advancedOpen } } if (advancedOpen) { RowLine(fg) { Name("Replace vault from backup", com.peachpasswords.ui.theme.PeachColors.SyncBusy) SubtleButton("open", com.peachpasswords.ui.theme.PeachColors.SyncBusy) { onNavigate(PeachNav.Import) } } RowLine(fg) { Name("Destroy vault", com.peachpasswords.ui.theme.PeachColors.Breach) SubtleButton("destroy", com.peachpasswords.ui.theme.PeachColors.Breach) { onNavigate(PeachNav.Panic) } } } } /* ──────────────────────────────── Sync ────────────────────────────────── */ @Composable private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) { SubLabel("PAIRING", fg, top = 0.dp) RowLine(fg) { Column(Modifier.weight(1f)) { Row(verticalAlignment = Alignment.CenterVertically) { Text("Peach Sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp); ProBadge(fg) } Text( "Pair nearby devices by chirp and keep encrypted vault blobs in step without a central account.", color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp, modifier = Modifier.padding(top = 2.dp), ) } } RowLine(fg) { Name("Status", fg); ValueText("Requires Pro", fg) } RowLine(fg) { Name("Sync hub", fg); SubtleButton("open", fg) { onNavigate(PeachNav.ChirpPair) } } SubLabel("DEVICE FLOW", fg) RowLine(fg) { Name("Pair new device", fg); SubtleButton("pair", fg) { onNavigate(PeachNav.ChirpPair) } } Hint("Sync uses the same zero-knowledge vault format as backup and restore; pairing authorizes a device, not a cloud account.", fg) } /* ────────────────────────────── Shortcuts ──────────────────────────────── */ @Composable private fun ShortcutsBody(fg: Color) { val bindings = listOf( "Copy password" to "⌘C", "Copy username" to "⌘⇧C", "Open entry" to "↵", "Edit entry" to "E", "New entry" to "⌘N", "Search" to "/", ) SubLabel("KEYBINDINGS", fg, top = 0.dp) Hint("Shortcuts apply when a hardware keyboard is attached. Defaults shown below.", fg) Spacer(Modifier.height(8.dp)) bindings.forEach { (label, key) -> RowLine(fg) { Name(label, fg) Box( Modifier.clip(RoundedCornerShape(4.dp)).background(fg.copy(alpha = 0.06f)) .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(4.dp)) .padding(horizontal = 7.dp, vertical = 2.dp), ) { Text(key, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp) } } } } /* ──────────────────────────────── Pro ─────────────────────────────────── */ @Composable private fun ProBody(fg: Color) { val ctx = LocalContext.current val features = listOf( "Peach Sync" to "Encrypted · peer-to-peer", "Peach Codex" to "Restore from paper", "Passkeys" to "Zero-knowledge WebAuthn", "Advanced Vault Health" to "Reuse · age · exposure", "Canary entries" to "Detects vault compromise", "Duress vault" to "Decoy under coercion", ) Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em) Text( "Everything, everywhere.", modifier = Modifier.padding(top = 8.dp), color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp, ) Text( "One key unlocks every Pro feature — for the lifetime of the app.", modifier = Modifier.padding(top = 6.dp), color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp, ) Spacer(Modifier.height(12.dp)) features.forEachIndexed { i, (name, desc) -> RowLine(fg) { Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp)) Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp) } Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp) } } Spacer(Modifier.height(14.dp)) Text( "$39", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp, ) Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em) Spacer(Modifier.height(10.dp)) Box( Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)) .background(fg.copy(alpha = 0.16f)) .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp)) .clickable { runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) } } .padding(vertical = 12.dp), contentAlignment = Alignment.Center, ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) } Hint("Already have a key? License activation arrives with Pro sync in a later update.", fg) } /* ────────────────────────────── Feedback ───────────────────────────────── */ @OptIn(ExperimentalLayoutApi::class) @Composable private fun FeedbackBody(fg: Color) { val categories = listOf("Bug report", "Feature request", "Question", "Other") var category by remember { mutableStateOf(categories[0]) } var message by remember { mutableStateOf("") } var sent by remember { mutableStateOf(false) } if (sent) { Box( Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f)) .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp), ) { Column { Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp) Text("Your note is in the queue. Someone will process it soon.", color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 12.sp, modifier = Modifier.padding(top = 4.dp)) } } return } Text("Help us improve Peach. Every report goes directly to our inbox.", color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp) SubLabel("TYPE", fg) FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) { categories.forEach { cat -> Pill(cat, category == cat, fg) { category = cat } } } SubLabel("MESSAGE", fg) Box( Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp)) .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp)) .padding(10.dp), ) { if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp) BasicTextField( value = message, onValueChange = { message = it }, textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp), cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(), ) } Spacer(Modifier.height(8.dp)) SubtleButton("Send", fg) { if (message.isNotBlank()) sent = true } Hint("Sent anonymously · no account required", fg) }