SettingsCardBodies.kt

35.1 KB · raw

1package com.peachpasswords.ui.settings23import android.content.Intent4import android.net.Uri5import androidx.compose.animation.AnimatedVisibility6import androidx.compose.animation.core.animateDpAsState7import androidx.compose.foundation.background8import androidx.compose.foundation.border9import androidx.compose.foundation.clickable10import androidx.compose.foundation.layout.Arrangement11import androidx.compose.foundation.layout.Box12import androidx.compose.foundation.layout.Column13import androidx.compose.foundation.layout.FlowRow14import androidx.compose.foundation.layout.ExperimentalLayoutApi15import androidx.compose.foundation.layout.Row16import androidx.compose.foundation.layout.RowScope17import androidx.compose.foundation.layout.Spacer18import androidx.compose.foundation.layout.fillMaxWidth19import androidx.compose.foundation.layout.height20import androidx.compose.foundation.layout.padding21import androidx.compose.foundation.layout.size22import androidx.compose.foundation.layout.width23import androidx.compose.foundation.shape.CircleShape24import androidx.compose.foundation.shape.RoundedCornerShape25import androidx.compose.foundation.text.BasicTextField26import androidx.compose.runtime.Composable27import androidx.compose.material3.CircularProgressIndicator28import androidx.compose.runtime.DisposableEffect29import androidx.compose.runtime.collectAsState30import androidx.compose.runtime.getValue31import com.peachpasswords.feedback.FeedbackState32import com.peachpasswords.ui.theme.LocalPeachAccent33import com.peachpasswords.vault.DuressAction34import com.peachpasswords.ui.theme.peachColors35import androidx.compose.runtime.mutableStateOf36import androidx.compose.runtime.remember37import androidx.compose.runtime.rememberCoroutineScope38import androidx.compose.runtime.setValue39import androidx.compose.ui.Alignment40import androidx.compose.ui.Modifier41import androidx.compose.ui.draw.clip42import androidx.compose.ui.graphics.Color43import androidx.compose.ui.graphics.SolidColor44import androidx.compose.ui.platform.LocalContext45import androidx.compose.ui.text.TextStyle46import androidx.compose.ui.text.font.FontStyle47import androidx.compose.ui.text.input.PasswordVisualTransformation48import androidx.compose.ui.unit.Dp49import androidx.compose.ui.unit.dp50import androidx.compose.ui.unit.em51import androidx.compose.ui.unit.sp52import androidx.compose.material3.Text53import com.peachpasswords.ui.PeachNav54import com.peachpasswords.ui.theme.ACCENT_COLORS55import com.peachpasswords.ui.theme.PeachType56import com.peachpasswords.vault.VaultSettings57import kotlinx.coroutines.launch5859private const val PRO_URL = "https://buy.polar.sh/polar_cl_IXSFIPojx67rcOTksn8LkH5mnU3osPHtYqBIl1eyuIz"6061/**62 * Body content for the active stack card. Everything is tinted with the card's63 * own foreground [fg] (the browser's `currentColor` convention), so each card's64 * rows inherit its palette. Rows whose backend doesn't exist yet (duress,65 * canary, license activation) render their browser visual but defer the action66 * to a later phase — noted inline where that's the case.67 */68@Composable69fun CardBody(70    id: CardId,71    fg: Color,72    vm: SettingsViewModel,73    settings: VaultSettings,74    entriesCount: Int,75    onNavigate: (PeachNav) -> Unit,76) {77    when (id) {78        CardId.Appearance -> AppearanceBody(fg, vm, settings)79        CardId.Protection -> ProtectionBody(fg, vm, settings, onNavigate)80        CardId.Vault -> VaultBody(fg, vm, settings, entriesCount, onNavigate)81        CardId.Sync -> SyncBody(fg, onNavigate)82        CardId.Shortcuts -> ShortcutsBody(fg)83        CardId.Pro -> ProBody(fg, vm)84        CardId.Feedback -> FeedbackBody(fg, vm)85    }86}8788/* ─────────────────────────  shared row vocabulary  ───────────────────────── */8990@Composable91private fun SubLabel(text: String, fg: Color, top: Dp = 14.dp) {92    Text(93        text,94        modifier = Modifier.padding(top = top, bottom = 4.dp),95        color = fg.copy(alpha = 0.58f),96        fontFamily = PeachType.Mono,97        fontSize = 8.sp,98        letterSpacing = 0.22.em,99    )100}101102@Composable103private fun RowLine(fg: Color, content: @Composable RowScope.() -> Unit) {104    Row(105        Modifier.fillMaxWidth().padding(vertical = 9.dp),106        verticalAlignment = Alignment.CenterVertically,107        horizontalArrangement = Arrangement.SpaceBetween,108        content = content,109    )110    Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.12f)))111}112113@Composable114private fun RowScope.Name(text: String, fg: Color) {115    Text(text, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp, modifier = Modifier.weight(1f))116}117118@Composable119private fun ValueText(text: String, fg: Color) {120    Text(text, color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Mono, fontSize = 11.sp)121}122123@Composable124private fun SubtleButton(label: String, fg: Color, onClick: () -> Unit) {125    Box(126        Modifier.clip(RoundedCornerShape(8.dp))127            .border(1.dp, fg.copy(alpha = 0.28f), RoundedCornerShape(8.dp))128            .background(fg.copy(alpha = 0.08f))129            .clickable(onClick = onClick)130            .padding(horizontal = 12.dp, vertical = 6.dp),131    ) {132        Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp)133    }134}135136@Composable137private fun Toggle(on: Boolean, fg: Color, onToggle: (Boolean) -> Unit) {138    val knob by animateDpAsState(if (on) 16.dp else 2.dp, label = "knob")139    Box(140        Modifier.size(width = 34.dp, height = 20.dp).clip(RoundedCornerShape(999.dp))141            .background(if (on) fg.copy(alpha = 0.28f) else fg.copy(alpha = 0.08f))142            .border(1.dp, fg.copy(alpha = if (on) 0.5f else 0.32f), RoundedCornerShape(999.dp))143            .clickable { onToggle(!on) },144    ) {145        Box(146            Modifier.padding(top = 2.dp).width(16.dp).fillMaxWidth().height(16.dp)147                .padding(start = knob - 2.dp)148                .size(14.dp).clip(CircleShape)149                .background(if (on) fg else fg.copy(alpha = 0.58f)),150        )151    }152}153154@Composable155private fun Pill(label: String, active: Boolean, fg: Color, onClick: () -> Unit) {156    Box(157        Modifier.clip(RoundedCornerShape(999.dp))158            .border(1.dp, fg.copy(alpha = if (active) 0.55f else 0.32f), RoundedCornerShape(999.dp))159            .background(if (active) fg.copy(alpha = 0.18f) else Color.Transparent)160            .clickable(onClick = onClick)161            .padding(horizontal = 12.dp, vertical = 5.dp),162    ) {163        Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)164    }165}166167@Composable168private fun ProBadge(fg: Color) {169    Box(170        Modifier.padding(start = 6.dp).clip(RoundedCornerShape(4.dp))171            .background(fg.copy(alpha = 0.16f)).padding(horizontal = 5.dp, vertical = 1.dp),172    ) {173        Text("Pro", color = fg.copy(alpha = 0.85f), fontFamily = PeachType.Mono, fontSize = 8.sp)174    }175}176177@Composable178private fun Hint(text: String, fg: Color) {179    Text(180        text,181        modifier = Modifier.padding(top = 6.dp),182        color = fg.copy(alpha = 0.6f),183        fontFamily = PeachType.Display,184        fontStyle = FontStyle.Italic,185        fontSize = 11.5.sp,186        lineHeight = 16.sp,187    )188}189190/* ──────────────────────────────  Appearance  ─────────────────────────────── */191192@OptIn(ExperimentalLayoutApi::class)193@Composable194private fun AppearanceBody(fg: Color, vm: SettingsViewModel, s: VaultSettings) {195    SubLabel("THEME", fg, top = 0.dp)196    RowLine(fg) {197        Name("Theme", fg)198        // Cycle dark → light → system → dark. The button shows the current mode;199        // tapping advances to the next.200        val (label, next) = when (s.theme) {201            "light" -> "Light" to "system"202            "system" -> "System" to "dark"203            else -> "Dark" to "light"204        }205        SubtleButton(label, fg) { vm.setTheme(next) }206    }207    SubLabel("ACCENT", fg)208    FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {209        ACCENT_COLORS.forEach { (name, color) ->210            Box(211                Modifier.size(22.dp).clip(CircleShape).background(color)212                    .border(213                        if (s.accentColor == name) 2.dp else 1.dp,214                        if (s.accentColor == name) fg else fg.copy(alpha = 0.2f),215                        CircleShape,216                    )217                    .clickable { vm.setAccent(name) },218            )219        }220    }221    SubLabel("TEXT SIZE", fg)222    RowLine(fg) {223        Name("Size", fg)224        Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {225            Pill("Default", s.textSize == "medium", fg) { vm.setTextSize("medium") }226            Pill("Large", s.textSize == "large", fg) { vm.setTextSize("large") }227        }228    }229    SubLabel("MOTION", fg)230    RowLine(fg) {231        Name("Reduce motion", fg)232        SubtleButton(if (s.reduceMotion) "On" else "Off", fg) { vm.setReduceMotion(!s.reduceMotion) }233    }234}235236/* ──────────────────────────────  Protection  ─────────────────────────────── */237238@Composable239private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) {240    val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never")241    val current = s.autoLockMinutes ?: 0242243    SubLabel("LOCKING", fg, top = 0.dp)244    RowLine(fg) {245        Name("Auto-lock after", fg)246        val idx = lockOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)247        SubtleButton(lockOptions[idx].second, fg) {248            val next = lockOptions[(idx + 1) % lockOptions.size].first249            vm.setAutoLockMinutes(if (next == 0) 0 else next)250        }251    }252    SubLabel("BIOMETRICS", fg)253    val bioActivity = LocalContext.current as? androidx.fragment.app.FragmentActivity254    RowLine(fg) {255        Name("Unlock with biometrics", fg)256        Toggle(s.biometricsEnabled, fg) { on ->257            if (on && bioActivity != null) vm.enableBiometrics(bioActivity) else vm.disableBiometrics()258        }259    }260    val bioError = com.peachpasswords.ui.lock.Biometrics.statusMessage(LocalContext.current)261    if (bioError != null) {262        Text(263            bioError,264            color = com.peachpasswords.ui.theme.peachColors.Breach,265            fontFamily = PeachType.Mono, fontSize = 10.sp,266            modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 4.dp),267        )268    }269    SubLabel("RECOVERY", fg)270    RowLine(fg) {271        Name("View recovery words", fg)272        SubtleButton("view", fg) { onNavigate(PeachNav.RecoveryView) }273    }274    SubLabel("BREACH PROTECTION", fg)275    RowLine(fg) {276        Name("Breach monitoring", fg)277        Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }278    }279280    SubLabel("MASTER PASSWORD", fg)281    ChangePasswordRow(fg, vm)282283    SubLabel("DURESS PASSWORD", fg)284    val duressIsPro by vm.isPro.collectAsState()285    if (!duressIsPro) {286        RowLine(fg) {287            Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {288                Name("Duress password", fg); ProBadge(fg)289            }290            ValueText("off", fg)291        }292        Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Pro feature.", fg)293    } else {294        DuressSection(fg, vm)295    }296}297298@Composable299private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {300    var open by remember { mutableStateOf(false) }301    var current by remember { mutableStateOf("") }302    var next by remember { mutableStateOf("") }303    var confirm by remember { mutableStateOf("") }304    var error by remember { mutableStateOf<String?>(null) }305    var done by remember { mutableStateOf(false) }306    val scope = rememberCoroutineScope()307308    RowLine(fg) {309        Name("Master password", fg)310        SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }311    }312    AnimatedVisibility(open) {313        Column(Modifier.fillMaxWidth().padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {314            PwField("current password", current, fg) { current = it }315            PwField("new password (min 12 chars)", next, fg) { next = it }316            PwField("confirm new password", confirm, fg) { confirm = it }317            error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }318            if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)319            SubtleButton("save new password", fg) {320                error = when {321                    current.isBlank() -> "enter your current password"322                    next.length < 12 -> "new password must be at least 12 characters"323                    next != confirm -> "new passwords do not match"324                    next == current -> "new password must differ from current"325                    else -> null326                }327                if (error == null) scope.launch {328                    if (vm.changePassword(current, next)) {329                        current = ""; next = ""; confirm = ""; open = false; done = true330                    } else error = "incorrect current password"331                }332            }333        }334    }335}336337@Composable338private fun PwField(placeholder: String, value: String, fg: Color, onChange: (String) -> Unit) {339    Box(340        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))341            .background(Color(0x2E000000))342            .border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))343            .padding(horizontal = 10.dp, vertical = 10.dp),344    ) {345        if (value.isEmpty()) {346            Text(placeholder, color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Mono, fontSize = 12.sp)347        }348        BasicTextField(349            value = value,350            onValueChange = onChange,351            singleLine = true,352            textStyle = TextStyle(color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp),353            cursorBrush = SolidColor(fg),354            visualTransformation = PasswordVisualTransformation(),355            modifier = Modifier.fillMaxWidth(),356        )357    }358}359360/* ────────────────────────────────  Vault  ───────────────────────────────── */361362@Composable363private fun VaultBody(364    fg: Color,365    vm: SettingsViewModel,366    s: VaultSettings,367    entriesCount: Int,368    onNavigate: (PeachNav) -> Unit,369) {370    val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")371    val current = s.trashRetentionDays ?: 0372    val isPro by vm.isPro.collectAsState()373374    SubLabel("ENTRIES", fg, top = 0.dp)375    RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }376377    SubLabel("MAINTENANCE", fg)378    RowLine(fg) {379        Name("Trash auto-delete", fg)380        val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)381        SubtleButton(trashOptions[idx].second, fg) {382            vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)383        }384    }385    RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }386    RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }387388    SubLabel("DATA", fg)389    RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }390    RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }391    RowLine(fg) {392        Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }393        SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }394    }395    RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }396397    var advancedOpen by remember { mutableStateOf(false) }398    SubLabel("ADVANCED", fg)399    RowLine(fg) {400        Name("Advanced", fg)401        SubtleButton(if (advancedOpen) "hide" else "show", fg) { advancedOpen = !advancedOpen }402    }403    if (advancedOpen) {404        RowLine(fg) {405            Name("Replace vault from backup", com.peachpasswords.ui.theme.peachColors.SyncBusy)406            SubtleButton("open", com.peachpasswords.ui.theme.peachColors.SyncBusy) { onNavigate(PeachNav.Import) }407        }408        RowLine(fg) {409            Name("Destroy vault", com.peachpasswords.ui.theme.peachColors.Breach)410            SubtleButton("destroy", com.peachpasswords.ui.theme.peachColors.Breach) { onNavigate(PeachNav.Panic) }411        }412    }413}414415/* ────────────────────────────────  Sync  ────────────────────────────────── */416417@Composable418private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {419    SubLabel("PAIRING", fg, top = 0.dp)420    RowLine(fg) {421        Column(Modifier.weight(1f)) {422            Row(verticalAlignment = Alignment.CenterVertically) {423                Text("Peach Sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp); ProBadge(fg)424            }425            Text(426                "Pair nearby devices by chirp and keep encrypted vault blobs in step without a central account.",427                color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,428                modifier = Modifier.padding(top = 2.dp),429            )430        }431    }432    RowLine(fg) { Name("Status", fg); ValueText("Requires Pro", fg) }433    RowLine(fg) { Name("Sync hub", fg); SubtleButton("open", fg) { onNavigate(PeachNav.ChirpPair) } }434435    SubLabel("DEVICE FLOW", fg)436    RowLine(fg) { Name("Pair new device", fg); SubtleButton("pair", fg) { onNavigate(PeachNav.ChirpPair) } }437    Hint("Sync uses the same zero-knowledge vault format as backup and restore; pairing authorizes a device, not a cloud account.", fg)438}439440/* ──────────────────────────────  Shortcuts  ──────────────────────────────── */441442@Composable443private fun ShortcutsBody(fg: Color) {444    val bindings = listOf(445        "Copy password" to "⌘C", "Copy username" to "⌘⇧C", "Open entry" to "↵",446        "Edit entry" to "E", "New entry" to "⌘N", "Search" to "/",447    )448    SubLabel("KEYBINDINGS", fg, top = 0.dp)449    Hint("Shortcuts apply when a hardware keyboard is attached. Defaults shown below.", fg)450    Spacer(Modifier.height(8.dp))451    bindings.forEach { (label, key) ->452        RowLine(fg) {453            Name(label, fg)454            Box(455                Modifier.clip(RoundedCornerShape(4.dp)).background(fg.copy(alpha = 0.06f))456                    .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(4.dp))457                    .padding(horizontal = 7.dp, vertical = 2.dp),458            ) { Text(key, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp) }459        }460    }461}462463/* ────────────────────────────────  Pro  ─────────────────────────────────── */464465@Composable466private fun ProBody(fg: Color, vm: SettingsViewModel) {467    val ctx = LocalContext.current468    val isPro by vm.isPro.collectAsState()469    if (isPro) {470        ProActiveBody(fg, vm)471        return472    }473    val features = listOf(474        "Peach Sync" to "Encrypted · peer-to-peer",475        "Peach Codex" to "Restore from paper",476        "Passkeys" to "Zero-knowledge WebAuthn",477        "Advanced Vault Health" to "Reuse · age · exposure",478        "Canary entries" to "Detects vault compromise",479        "Duress vault" to "Decoy under coercion",480    )481    Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)482    Text(483        "Everything, everywhere.",484        modifier = Modifier.padding(top = 8.dp),485        color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,486    )487    Text(488        "One key unlocks every Pro feature — for the lifetime of the app.",489        modifier = Modifier.padding(top = 6.dp),490        color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,491    )492    Spacer(Modifier.height(12.dp))493    features.forEachIndexed { i, (name, desc) ->494        RowLine(fg) {495            Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {496                Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))497                Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)498            }499            Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)500        }501    }502    Spacer(Modifier.height(14.dp))503    Text(504        "$39",505        color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,506    )507    Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)508    Spacer(Modifier.height(10.dp))509    Box(510        Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))511            .background(fg.copy(alpha = 0.16f))512            .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))513            .clickable {514                runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }515            }516            .padding(vertical = 12.dp),517        contentAlignment = Alignment.Center,518    ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }519520    Spacer(Modifier.height(16.dp))521    Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)522    var key by remember { mutableStateOf("") }523    val activating by vm.activating.collectAsState()524    val activationError by vm.activationError.collectAsState()525    Box(526        Modifier.fillMaxWidth().padding(top = 6.dp)527            .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))528            .padding(horizontal = 12.dp, vertical = 10.dp),529    ) {530        BasicTextField(531            value = key,532            onValueChange = { key = it.uppercase(); vm.clearActivationError() },533            singleLine = true,534            textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),535            cursorBrush = SolidColor(fg),536            modifier = Modifier.fillMaxWidth(),537            decorationBox = { inner ->538                if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)539                inner()540            },541        )542    }543    if (activationError != null) {544        Text(activationError!!, color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))545    }546    Spacer(Modifier.height(8.dp))547    Box(548        Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))549            .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))550            .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))551            .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }552            .padding(vertical = 12.dp),553        contentAlignment = Alignment.Center,554    ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }555}556557@Composable558private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {559    val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")560    Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {561        com.peachpasswords.ui.components.PeachMark(size = 60.dp)562    }563    Text(564        "Peach Pro",565        modifier = Modifier.fillMaxWidth(),566        color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,567        textAlign = androidx.compose.ui.text.style.TextAlign.Center,568    )569    Text(570        "active · yours forever",571        modifier = Modifier.fillMaxWidth().padding(top = 4.dp),572        color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,573        textAlign = androidx.compose.ui.text.style.TextAlign.Center,574    )575    Spacer(Modifier.height(12.dp))576    features.forEachIndexed { i, name ->577        RowLine(fg) {578            Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {579                Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))580                Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)581            }582            Text("unlocked", color = com.peachpasswords.ui.theme.peachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)583        }584    }585    Spacer(Modifier.height(12.dp))586    Box(587        Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))588            .border(1.dp, com.peachpasswords.ui.theme.peachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))589            .clickable { vm.deactivate() }590            .padding(vertical = 12.dp),591        contentAlignment = Alignment.Center,592    ) { Text("Deactivate", color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }593}594595/* ──────────────────────────────  Feedback  ───────────────────────────────── */596597@OptIn(ExperimentalLayoutApi::class)598@Composable599private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {600    val categories = listOf("Bug report", "Feature request", "Question", "Other")601    var category by remember { mutableStateOf(categories[0]) }602    var message by remember { mutableStateOf("") }603    val state by vm.feedbackState.collectAsState()604605    // Reset transient state when the card leaves composition so reopening starts fresh.606    DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }607608    if (state is FeedbackState.Sent) {609        Box(610            Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))611                .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),612        ) {613            Column {614                Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)615                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))616            }617        }618        return619    }620621    val sending = state is FeedbackState.Sending622623    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)624    SubLabel("TYPE", fg)625    FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {626        categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }627    }628    SubLabel("MESSAGE", fg)629    Box(630        Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))631            .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))632            .padding(10.dp),633    ) {634        if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)635        BasicTextField(636            value = message, onValueChange = { message = it },637            enabled = !sending,638            textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),639            cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),640        )641    }642    Spacer(Modifier.height(8.dp))643644    Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {645        val canSend = !sending && message.isNotBlank()646        Box(647            Modifier.clip(RoundedCornerShape(8.dp))648                .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))649                .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))650                .clickable(enabled = canSend) { vm.sendFeedback(category, message) }651                .padding(horizontal = 12.dp, vertical = 6.dp),652        ) {653            Text(654                if (state is FeedbackState.Error) "Retry" else "Send",655                color = fg.copy(alpha = if (canSend) 1f else 0.4f),656                fontFamily = PeachType.Mono, fontSize = 11.sp,657            )658        }659        if (sending) {660            CircularProgressIndicator(661                color = LocalPeachAccent.current,662                strokeWidth = 2.dp,663                modifier = Modifier.size(16.dp),664            )665        }666    }667668    (state as? FeedbackState.Error)?.let { err ->669        Text(670            err.message,671            modifier = Modifier.padding(top = 8.dp),672            color = peachColors.Breach,673            fontFamily = PeachType.Mono,674            fontSize = 11.sp,675            lineHeight = 15.sp,676        )677    }678679    Hint("Sent anonymously · no account required", fg)680}681682/* ──────────────────────────────  D13 Duress  ─────────────────────────────── */683684@Composable685internal fun DuressSection(fg: Color, vm: SettingsViewModel) {686    val configured by vm.duressConfigured.collectAsState()687    if (configured) DuressActiveState(fg, vm) else DuressForm(fg, vm)688}689690@Composable691private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {692    Text(693        "Duress password is active",694        color = peachColors.HealthOk,695        fontFamily = PeachType.Mono,696        fontSize = 11.sp,697        modifier = Modifier.padding(top = 6.dp),698    )699    Spacer(Modifier.height(8.dp))700    DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }701    Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)702}703704@Composable705private fun DuressForm(fg: Color, vm: SettingsViewModel) {706    var enabled by remember { mutableStateOf(false) }707    var password by remember { mutableStateOf("") }708    var confirm by remember { mutableStateOf("") }709    var action by remember { mutableStateOf(DuressAction.DECOY) }710    var error by remember { mutableStateOf<String?>(null) }711    val scope = rememberCoroutineScope()712713    RowLine(fg) {714        Name("Duress password", fg)715        Toggle(enabled, fg) { on ->716            enabled = on717            if (!on) { password = ""; confirm = ""; error = null }718        }719    }720    Text(721        "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",722        color = fg.copy(alpha = 0.7f),723        fontFamily = PeachType.Mono,724        fontSize = 10.sp,725        modifier = Modifier.padding(top = 6.dp),726    )727728    AnimatedVisibility(enabled) {729        Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {730            PwField("DURESS PASSWORD", password, fg) { password = it; error = null }731            PwField("CONFIRM DURESS PASSWORD", confirm, fg) { confirm = it; error = null }732733            Text(734                "When your duress password is entered at the lock screen, Peach will:",735                color = fg.copy(alpha = 0.7f),736                fontFamily = PeachType.Mono,737                fontSize = 10.sp,738                modifier = Modifier.padding(top = 4.dp),739            )740741            DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }742            DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }743744            error?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }745746            val canSave = password.isNotBlank() && confirm.isNotBlank()747            DuressSaveButton("Save duress password", fg, canSave) {748                error = when {749                    password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"750                    password != confirm -> "Passwords do not match"751                    else -> null752                }753                if (error == null) scope.launch {754                    if (vm.saveDuress(password, action)) {755                        password = ""; confirm = ""; enabled = false756                    } else {757                        error = "Couldn't save duress password"758                    }759                }760            }761        }762    }763}764765@Composable766private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {767    val accent = LocalPeachAccent.current768    Row(769        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),770        verticalAlignment = Alignment.CenterVertically,771        horizontalArrangement = Arrangement.spacedBy(10.dp),772    ) {773        Box(774            Modifier.size(16.dp).clip(CircleShape)775                .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),776            contentAlignment = Alignment.Center,777        ) {778            if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))779        }780        Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)781    }782}783784@Composable785private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {786    val accent = LocalPeachAccent.current787    val tint = if (enabled) accent else fg.copy(alpha = 0.3f)788    Box(789        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))790            .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))791            .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))792            .let { if (enabled) it.clickable(onClick = onClick) else it }793            .padding(vertical = 11.dp),794        contentAlignment = Alignment.Center,795    ) {796        Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)797    }798}799800@Composable801private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {802    Box(803        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))804            .border(1.dp, peachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))805            .clickable(onClick = onClick)806            .padding(vertical = 11.dp),807        contentAlignment = Alignment.Center,808    ) {809        Text(label, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)810    }811}