SettingsCardBodies.kt

34.9 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        SubtleButton(if (s.theme == "dark") "Switch to light" else "Switch to dark", fg) {199            vm.setTheme(if (s.theme == "dark") "light" else "dark")200        }201    }202    SubLabel("ACCENT", fg)203    FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {204        ACCENT_COLORS.forEach { (name, color) ->205            Box(206                Modifier.size(22.dp).clip(CircleShape).background(color)207                    .border(208                        if (s.accentColor == name) 2.dp else 1.dp,209                        if (s.accentColor == name) fg else fg.copy(alpha = 0.2f),210                        CircleShape,211                    )212                    .clickable { vm.setAccent(name) },213            )214        }215    }216    SubLabel("TEXT SIZE", fg)217    RowLine(fg) {218        Name("Size", fg)219        Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {220            Pill("Default", s.textSize == "medium", fg) { vm.setTextSize("medium") }221            Pill("Large", s.textSize == "large", fg) { vm.setTextSize("large") }222        }223    }224    SubLabel("MOTION", fg)225    RowLine(fg) {226        Name("Reduce motion", fg)227        SubtleButton(if (s.reduceMotion) "On" else "Off", fg) { vm.setReduceMotion(!s.reduceMotion) }228    }229}230231/* ──────────────────────────────  Protection  ─────────────────────────────── */232233@Composable234private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) {235    val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never")236    val current = s.autoLockMinutes ?: 0237238    SubLabel("LOCKING", fg, top = 0.dp)239    RowLine(fg) {240        Name("Auto-lock after", fg)241        val idx = lockOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)242        SubtleButton(lockOptions[idx].second, fg) {243            val next = lockOptions[(idx + 1) % lockOptions.size].first244            vm.setAutoLockMinutes(if (next == 0) 0 else next)245        }246    }247    SubLabel("BIOMETRICS", fg)248    val bioActivity = LocalContext.current as? androidx.fragment.app.FragmentActivity249    RowLine(fg) {250        Name("Unlock with biometrics", fg)251        Toggle(s.biometricsEnabled, fg) { on ->252            if (on && bioActivity != null) vm.enableBiometrics(bioActivity) else vm.disableBiometrics()253        }254    }255    val bioError = com.peachpasswords.ui.lock.Biometrics.statusMessage(LocalContext.current)256    if (bioError != null) {257        Text(258            bioError,259            color = com.peachpasswords.ui.theme.PeachColors.Breach,260            fontFamily = PeachType.Mono, fontSize = 10.sp,261            modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 4.dp),262        )263    }264    SubLabel("RECOVERY", fg)265    RowLine(fg) {266        Name("View recovery words", fg)267        SubtleButton("view", fg) { onNavigate(PeachNav.RecoveryView) }268    }269    SubLabel("BREACH PROTECTION", fg)270    RowLine(fg) {271        Name("Breach monitoring", fg)272        Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }273    }274275    SubLabel("MASTER PASSWORD", fg)276    ChangePasswordRow(fg, vm)277278    SubLabel("DURESS PASSWORD", fg)279    val duressIsPro by vm.isPro.collectAsState()280    if (!duressIsPro) {281        RowLine(fg) {282            Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {283                Name("Duress password", fg); ProBadge(fg)284            }285            ValueText("off", fg)286        }287        Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Pro feature.", fg)288    } else {289        DuressSection(fg, vm)290    }291}292293@Composable294private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {295    var open by remember { mutableStateOf(false) }296    var current by remember { mutableStateOf("") }297    var next by remember { mutableStateOf("") }298    var confirm by remember { mutableStateOf("") }299    var error by remember { mutableStateOf<String?>(null) }300    var done by remember { mutableStateOf(false) }301    val scope = rememberCoroutineScope()302303    RowLine(fg) {304        Name("Master password", fg)305        SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }306    }307    AnimatedVisibility(open) {308        Column(Modifier.fillMaxWidth().padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {309            PwField("current password", current, fg) { current = it }310            PwField("new password (min 12 chars)", next, fg) { next = it }311            PwField("confirm new password", confirm, fg) { confirm = it }312            error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }313            if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)314            SubtleButton("save new password", fg) {315                error = when {316                    current.isBlank() -> "enter your current password"317                    next.length < 12 -> "new password must be at least 12 characters"318                    next != confirm -> "new passwords do not match"319                    next == current -> "new password must differ from current"320                    else -> null321                }322                if (error == null) scope.launch {323                    if (vm.changePassword(current, next)) {324                        current = ""; next = ""; confirm = ""; open = false; done = true325                    } else error = "incorrect current password"326                }327            }328        }329    }330}331332@Composable333private fun PwField(placeholder: String, value: String, fg: Color, onChange: (String) -> Unit) {334    Box(335        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))336            .background(Color(0x2E000000))337            .border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))338            .padding(horizontal = 10.dp, vertical = 10.dp),339    ) {340        if (value.isEmpty()) {341            Text(placeholder, color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Mono, fontSize = 12.sp)342        }343        BasicTextField(344            value = value,345            onValueChange = onChange,346            singleLine = true,347            textStyle = TextStyle(color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp),348            cursorBrush = SolidColor(fg),349            visualTransformation = PasswordVisualTransformation(),350            modifier = Modifier.fillMaxWidth(),351        )352    }353}354355/* ────────────────────────────────  Vault  ───────────────────────────────── */356357@Composable358private fun VaultBody(359    fg: Color,360    vm: SettingsViewModel,361    s: VaultSettings,362    entriesCount: Int,363    onNavigate: (PeachNav) -> Unit,364) {365    val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")366    val current = s.trashRetentionDays ?: 0367    val isPro by vm.isPro.collectAsState()368369    SubLabel("ENTRIES", fg, top = 0.dp)370    RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }371372    SubLabel("MAINTENANCE", fg)373    RowLine(fg) {374        Name("Trash auto-delete", fg)375        val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)376        SubtleButton(trashOptions[idx].second, fg) {377            vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)378        }379    }380    RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }381    RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }382383    SubLabel("DATA", fg)384    RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }385    RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }386    RowLine(fg) {387        Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }388        SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }389    }390    RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }391392    var advancedOpen by remember { mutableStateOf(false) }393    SubLabel("ADVANCED", fg)394    RowLine(fg) {395        Name("Advanced", fg)396        SubtleButton(if (advancedOpen) "hide" else "show", fg) { advancedOpen = !advancedOpen }397    }398    if (advancedOpen) {399        RowLine(fg) {400            Name("Replace vault from backup", com.peachpasswords.ui.theme.PeachColors.SyncBusy)401            SubtleButton("open", com.peachpasswords.ui.theme.PeachColors.SyncBusy) { onNavigate(PeachNav.Import) }402        }403        RowLine(fg) {404            Name("Destroy vault", com.peachpasswords.ui.theme.PeachColors.Breach)405            SubtleButton("destroy", com.peachpasswords.ui.theme.PeachColors.Breach) { onNavigate(PeachNav.Panic) }406        }407    }408}409410/* ────────────────────────────────  Sync  ────────────────────────────────── */411412@Composable413private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {414    SubLabel("PAIRING", fg, top = 0.dp)415    RowLine(fg) {416        Column(Modifier.weight(1f)) {417            Row(verticalAlignment = Alignment.CenterVertically) {418                Text("Peach Sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp); ProBadge(fg)419            }420            Text(421                "Pair nearby devices by chirp and keep encrypted vault blobs in step without a central account.",422                color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,423                modifier = Modifier.padding(top = 2.dp),424            )425        }426    }427    RowLine(fg) { Name("Status", fg); ValueText("Requires Pro", fg) }428    RowLine(fg) { Name("Sync hub", fg); SubtleButton("open", fg) { onNavigate(PeachNav.ChirpPair) } }429430    SubLabel("DEVICE FLOW", fg)431    RowLine(fg) { Name("Pair new device", fg); SubtleButton("pair", fg) { onNavigate(PeachNav.ChirpPair) } }432    Hint("Sync uses the same zero-knowledge vault format as backup and restore; pairing authorizes a device, not a cloud account.", fg)433}434435/* ──────────────────────────────  Shortcuts  ──────────────────────────────── */436437@Composable438private fun ShortcutsBody(fg: Color) {439    val bindings = listOf(440        "Copy password" to "⌘C", "Copy username" to "⌘⇧C", "Open entry" to "↵",441        "Edit entry" to "E", "New entry" to "⌘N", "Search" to "/",442    )443    SubLabel("KEYBINDINGS", fg, top = 0.dp)444    Hint("Shortcuts apply when a hardware keyboard is attached. Defaults shown below.", fg)445    Spacer(Modifier.height(8.dp))446    bindings.forEach { (label, key) ->447        RowLine(fg) {448            Name(label, fg)449            Box(450                Modifier.clip(RoundedCornerShape(4.dp)).background(fg.copy(alpha = 0.06f))451                    .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(4.dp))452                    .padding(horizontal = 7.dp, vertical = 2.dp),453            ) { Text(key, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp) }454        }455    }456}457458/* ────────────────────────────────  Pro  ─────────────────────────────────── */459460@Composable461private fun ProBody(fg: Color, vm: SettingsViewModel) {462    val ctx = LocalContext.current463    val isPro by vm.isPro.collectAsState()464    if (isPro) {465        ProActiveBody(fg, vm)466        return467    }468    val features = listOf(469        "Peach Sync" to "Encrypted · peer-to-peer",470        "Peach Codex" to "Restore from paper",471        "Passkeys" to "Zero-knowledge WebAuthn",472        "Advanced Vault Health" to "Reuse · age · exposure",473        "Canary entries" to "Detects vault compromise",474        "Duress vault" to "Decoy under coercion",475    )476    Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)477    Text(478        "Everything, everywhere.",479        modifier = Modifier.padding(top = 8.dp),480        color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,481    )482    Text(483        "One key unlocks every Pro feature — for the lifetime of the app.",484        modifier = Modifier.padding(top = 6.dp),485        color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,486    )487    Spacer(Modifier.height(12.dp))488    features.forEachIndexed { i, (name, desc) ->489        RowLine(fg) {490            Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {491                Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))492                Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)493            }494            Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)495        }496    }497    Spacer(Modifier.height(14.dp))498    Text(499        "$39",500        color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,501    )502    Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)503    Spacer(Modifier.height(10.dp))504    Box(505        Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))506            .background(fg.copy(alpha = 0.16f))507            .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))508            .clickable {509                runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }510            }511            .padding(vertical = 12.dp),512        contentAlignment = Alignment.Center,513    ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }514515    Spacer(Modifier.height(16.dp))516    Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)517    var key by remember { mutableStateOf("") }518    val activating by vm.activating.collectAsState()519    val activationError by vm.activationError.collectAsState()520    Box(521        Modifier.fillMaxWidth().padding(top = 6.dp)522            .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))523            .padding(horizontal = 12.dp, vertical = 10.dp),524    ) {525        BasicTextField(526            value = key,527            onValueChange = { key = it.uppercase(); vm.clearActivationError() },528            singleLine = true,529            textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),530            cursorBrush = SolidColor(fg),531            modifier = Modifier.fillMaxWidth(),532            decorationBox = { inner ->533                if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)534                inner()535            },536        )537    }538    if (activationError != null) {539        Text(activationError!!, color = com.peachpasswords.ui.theme.PeachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))540    }541    Spacer(Modifier.height(8.dp))542    Box(543        Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))544            .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))545            .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))546            .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }547            .padding(vertical = 12.dp),548        contentAlignment = Alignment.Center,549    ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }550}551552@Composable553private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {554    val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")555    Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {556        com.peachpasswords.ui.components.PeachMark(size = 60.dp)557    }558    Text(559        "Peach Pro",560        modifier = Modifier.fillMaxWidth(),561        color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,562        textAlign = androidx.compose.ui.text.style.TextAlign.Center,563    )564    Text(565        "active · yours forever",566        modifier = Modifier.fillMaxWidth().padding(top = 4.dp),567        color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,568        textAlign = androidx.compose.ui.text.style.TextAlign.Center,569    )570    Spacer(Modifier.height(12.dp))571    features.forEachIndexed { i, name ->572        RowLine(fg) {573            Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {574                Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))575                Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)576            }577            Text("unlocked", color = com.peachpasswords.ui.theme.PeachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)578        }579    }580    Spacer(Modifier.height(12.dp))581    Box(582        Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))583            .border(1.dp, com.peachpasswords.ui.theme.PeachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))584            .clickable { vm.deactivate() }585            .padding(vertical = 12.dp),586        contentAlignment = Alignment.Center,587    ) { Text("Deactivate", color = com.peachpasswords.ui.theme.PeachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }588}589590/* ──────────────────────────────  Feedback  ───────────────────────────────── */591592@OptIn(ExperimentalLayoutApi::class)593@Composable594private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {595    val categories = listOf("Bug report", "Feature request", "Question", "Other")596    var category by remember { mutableStateOf(categories[0]) }597    var message by remember { mutableStateOf("") }598    val state by vm.feedbackState.collectAsState()599600    // Reset transient state when the card leaves composition so reopening starts fresh.601    DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }602603    if (state is FeedbackState.Sent) {604        Box(605            Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))606                .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),607        ) {608            Column {609                Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)610                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))611            }612        }613        return614    }615616    val sending = state is FeedbackState.Sending617618    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)619    SubLabel("TYPE", fg)620    FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {621        categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }622    }623    SubLabel("MESSAGE", fg)624    Box(625        Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))626            .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))627            .padding(10.dp),628    ) {629        if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)630        BasicTextField(631            value = message, onValueChange = { message = it },632            enabled = !sending,633            textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),634            cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),635        )636    }637    Spacer(Modifier.height(8.dp))638639    Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {640        val canSend = !sending && message.isNotBlank()641        Box(642            Modifier.clip(RoundedCornerShape(8.dp))643                .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))644                .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))645                .clickable(enabled = canSend) { vm.sendFeedback(category, message) }646                .padding(horizontal = 12.dp, vertical = 6.dp),647        ) {648            Text(649                if (state is FeedbackState.Error) "Retry" else "Send",650                color = fg.copy(alpha = if (canSend) 1f else 0.4f),651                fontFamily = PeachType.Mono, fontSize = 11.sp,652            )653        }654        if (sending) {655            CircularProgressIndicator(656                color = LocalPeachAccent.current,657                strokeWidth = 2.dp,658                modifier = Modifier.size(16.dp),659            )660        }661    }662663    (state as? FeedbackState.Error)?.let { err ->664        Text(665            err.message,666            modifier = Modifier.padding(top = 8.dp),667            color = PeachColors.Breach,668            fontFamily = PeachType.Mono,669            fontSize = 11.sp,670            lineHeight = 15.sp,671        )672    }673674    Hint("Sent anonymously · no account required", fg)675}676677/* ──────────────────────────────  D13 Duress  ─────────────────────────────── */678679@Composable680internal fun DuressSection(fg: Color, vm: SettingsViewModel) {681    val configured by vm.duressConfigured.collectAsState()682    if (configured) DuressActiveState(fg, vm) else DuressForm(fg, vm)683}684685@Composable686private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {687    Text(688        "Duress password is active",689        color = PeachColors.HealthOk,690        fontFamily = PeachType.Mono,691        fontSize = 11.sp,692        modifier = Modifier.padding(top = 6.dp),693    )694    Spacer(Modifier.height(8.dp))695    DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }696    Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)697}698699@Composable700private fun DuressForm(fg: Color, vm: SettingsViewModel) {701    var enabled by remember { mutableStateOf(false) }702    var password by remember { mutableStateOf("") }703    var confirm by remember { mutableStateOf("") }704    var action by remember { mutableStateOf(DuressAction.DECOY) }705    var error by remember { mutableStateOf<String?>(null) }706    val scope = rememberCoroutineScope()707708    RowLine(fg) {709        Name("Duress password", fg)710        Toggle(enabled, fg) { on ->711            enabled = on712            if (!on) { password = ""; confirm = ""; error = null }713        }714    }715    Text(716        "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",717        color = fg.copy(alpha = 0.7f),718        fontFamily = PeachType.Mono,719        fontSize = 10.sp,720        modifier = Modifier.padding(top = 6.dp),721    )722723    AnimatedVisibility(enabled) {724        Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {725            PwField("DURESS PASSWORD", password, fg) { password = it; error = null }726            PwField("CONFIRM DURESS PASSWORD", confirm, fg) { confirm = it; error = null }727728            Text(729                "When your duress password is entered at the lock screen, Peach will:",730                color = fg.copy(alpha = 0.7f),731                fontFamily = PeachType.Mono,732                fontSize = 10.sp,733                modifier = Modifier.padding(top = 4.dp),734            )735736            DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }737            DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }738739            error?.let { Text(it, color = PeachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }740741            val canSave = password.isNotBlank() && confirm.isNotBlank()742            DuressSaveButton("Save duress password", fg, canSave) {743                error = when {744                    password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"745                    password != confirm -> "Passwords do not match"746                    else -> null747                }748                if (error == null) scope.launch {749                    if (vm.saveDuress(password, action)) {750                        password = ""; confirm = ""; enabled = false751                    } else {752                        error = "Couldn't save duress password"753                    }754                }755            }756        }757    }758}759760@Composable761private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {762    val accent = LocalPeachAccent.current763    Row(764        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),765        verticalAlignment = Alignment.CenterVertically,766        horizontalArrangement = Arrangement.spacedBy(10.dp),767    ) {768        Box(769            Modifier.size(16.dp).clip(CircleShape)770                .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),771            contentAlignment = Alignment.Center,772        ) {773            if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))774        }775        Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)776    }777}778779@Composable780private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {781    val accent = LocalPeachAccent.current782    val tint = if (enabled) accent else fg.copy(alpha = 0.3f)783    Box(784        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))785            .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))786            .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))787            .let { if (enabled) it.clickable(onClick = onClick) else it }788            .padding(vertical = 11.dp),789        contentAlignment = Alignment.Center,790    ) {791        Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)792    }793}794795@Composable796private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {797    Box(798        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))799            .border(1.dp, PeachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))800            .clickable(onClick = onClick)801            .padding(vertical = 11.dp),802        contentAlignment = Alignment.Center,803    ) {804        Text(label, color = PeachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)805    }806}