SettingsCardBodies.kt

50.4 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.shared.PeachClipboard33import com.peachpasswords.sync.SyncStatus34import com.peachpasswords.ui.theme.LocalPeachAccent35import com.peachpasswords.vault.DuressAction36import com.peachpasswords.ui.theme.peachColors37import androidx.compose.runtime.mutableStateOf38import androidx.compose.runtime.remember39import androidx.compose.runtime.rememberCoroutineScope40import androidx.compose.runtime.setValue41import androidx.compose.ui.Alignment42import androidx.compose.ui.Modifier43import androidx.compose.ui.draw.clip44import androidx.compose.ui.graphics.Color45import androidx.compose.ui.graphics.SolidColor46import androidx.compose.ui.platform.LocalContext47import androidx.compose.ui.text.TextStyle48import androidx.compose.ui.text.font.FontStyle49import androidx.compose.ui.text.input.PasswordVisualTransformation50import androidx.compose.ui.unit.Dp51import androidx.compose.ui.unit.dp52import androidx.compose.ui.unit.em53import androidx.compose.ui.unit.sp54import androidx.compose.material3.Text55import com.peachpasswords.BuildConfig56import com.peachpasswords.ui.PeachNav57import com.peachpasswords.ui.components.PeachEmptyOrEndState58import com.peachpasswords.ui.components.PeachField59import com.peachpasswords.ui.sync.SyncViewModel60import com.peachpasswords.ui.theme.ACCENT_COLORS61import com.peachpasswords.ui.theme.PeachSpacing62import com.peachpasswords.ui.theme.PeachType63import androidx.hilt.navigation.compose.hiltViewModel64import com.peachpasswords.vault.VaultSettings65import com.peachpasswords.vault.VaultSnapshot66import kotlinx.coroutines.launch67import kotlinx.coroutines.delay68import java.text.SimpleDateFormat69import java.util.Date70import java.util.Locale7172private const val PRO_URL = "https://buy.polar.sh/polar_cl_IXSFIPojx67rcOTksn8LkH5mnU3osPHtYqBIl1eyuIz"7374/**75 * Body content for the active stack card. Everything is tinted with the card's76 * own foreground [fg] (the browser's `currentColor` convention), so each card's77 * rows inherit its palette. Rows whose backend doesn't exist yet (duress,78 * canary, license activation) render their browser visual but defer the action79 * to a later phase — noted inline where that's the case.80 */81@Composable82fun CardBody(83    id: CardId,84    fg: Color,85    vm: SettingsViewModel,86    settings: VaultSettings,87    entriesCount: Int,88    onNavigate: (PeachNav) -> Unit,89) {90    when (id) {91        CardId.Appearance -> AppearanceBody(fg, vm, settings)92        CardId.Protection -> ProtectionBody(fg, vm, settings, onNavigate)93        CardId.Vault -> VaultBody(fg, vm, settings, entriesCount, onNavigate)94        CardId.Sync -> SyncBody(fg, onNavigate)95        CardId.Shortcuts -> ShortcutsBody(fg)96        CardId.Pro -> ProBody(fg, vm)97        CardId.Feedback -> FeedbackBody(fg, vm)98    }99}100101/* ─────────────────────────  shared row vocabulary  ───────────────────────── */102103@Composable104private fun SubLabel(text: String, fg: Color, top: Dp = 14.dp) {105    Text(106        text,107        modifier = Modifier.padding(top = top, bottom = 4.dp),108        color = fg.copy(alpha = 0.58f),109        fontFamily = PeachType.Mono,110        fontSize = 8.sp,111        letterSpacing = 0.22.em,112    )113}114115@Composable116private fun RowLine(fg: Color, modifier: Modifier = Modifier, content: @Composable RowScope.() -> Unit) {117    Row(118        Modifier.fillMaxWidth().then(modifier).padding(vertical = 9.dp),119        verticalAlignment = Alignment.CenterVertically,120        horizontalArrangement = Arrangement.SpaceBetween,121        content = content,122    )123    Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.12f)))124}125126@Composable127private fun RowScope.Name(text: String, fg: Color) {128    Text(text, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp, modifier = Modifier.weight(1f))129}130131@Composable132private fun ValueText(text: String, fg: Color) {133    Text(text, color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Mono, fontSize = 11.sp)134}135136@Composable137private fun SubtleButton(label: String, fg: Color, onClick: () -> Unit) {138    Box(139        Modifier.clip(RoundedCornerShape(8.dp))140            .border(1.dp, fg.copy(alpha = 0.28f), RoundedCornerShape(8.dp))141            .background(fg.copy(alpha = 0.08f))142            .clickable(onClick = onClick)143            .padding(horizontal = 12.dp, vertical = 6.dp),144    ) {145        Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp)146    }147}148149@Composable150private fun Toggle(on: Boolean, fg: Color, onToggle: (Boolean) -> Unit) {151    val knob by animateDpAsState(if (on) 16.dp else 2.dp, label = "knob")152    Box(153        Modifier.size(width = 34.dp, height = 20.dp).clip(RoundedCornerShape(999.dp))154            .background(if (on) fg.copy(alpha = 0.28f) else fg.copy(alpha = 0.08f))155            .border(1.dp, fg.copy(alpha = if (on) 0.5f else 0.32f), RoundedCornerShape(999.dp))156            .clickable { onToggle(!on) },157    ) {158        Box(159            Modifier.padding(top = 2.dp).width(16.dp).fillMaxWidth().height(16.dp)160                .padding(start = knob - 2.dp)161                .size(14.dp).clip(CircleShape)162                .background(if (on) fg else fg.copy(alpha = 0.58f)),163        )164    }165}166167@Composable168private fun Pill(label: String, active: Boolean, fg: Color, onClick: () -> Unit) {169    Box(170        Modifier.clip(RoundedCornerShape(999.dp))171            .border(1.dp, fg.copy(alpha = if (active) 0.55f else 0.32f), RoundedCornerShape(999.dp))172            .background(if (active) fg.copy(alpha = 0.18f) else Color.Transparent)173            .clickable(onClick = onClick)174            .padding(horizontal = 12.dp, vertical = 5.dp),175    ) {176        Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)177    }178}179180@Composable181private fun ProBadge(fg: Color) {182    Box(183        Modifier.padding(start = 6.dp).clip(RoundedCornerShape(4.dp))184            .background(fg.copy(alpha = 0.16f)).padding(horizontal = 5.dp, vertical = 1.dp),185    ) {186        Text("Pro", color = fg.copy(alpha = 0.85f), fontFamily = PeachType.Mono, fontSize = 8.sp)187    }188}189190@Composable191private fun Hint(text: String, fg: Color) {192    Text(193        text,194        modifier = Modifier.padding(top = 6.dp),195        color = fg.copy(alpha = 0.6f),196        fontFamily = PeachType.Display,197        fontStyle = FontStyle.Italic,198        fontSize = 11.5.sp,199        lineHeight = 16.sp,200    )201}202203/* ──────────────────────────────  Appearance  ─────────────────────────────── */204205@OptIn(ExperimentalLayoutApi::class)206@Composable207private fun AppearanceBody(fg: Color, vm: SettingsViewModel, s: VaultSettings) {208    SubLabel("THEME", fg, top = 0.dp)209    RowLine(fg) {210        Name("Theme", fg)211        val (label, next) = when (s.theme) {212            "dark" -> "Switch to light" to "light"213            else -> "Switch to dark" to "dark"214        }215        SubtleButton(label, fg) { vm.setTheme(next) }216    }217    SubLabel("ACCENT", fg)218    FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {219        ACCENT_COLORS.forEach { (name, color) ->220            Box(221                Modifier.size(22.dp).clip(CircleShape).background(color)222                    .border(223                        if (s.accentColor == name) 2.dp else 1.dp,224                        if (s.accentColor == name) fg else fg.copy(alpha = 0.2f),225                        CircleShape,226                    )227                    .clickable { vm.setAccent(name) },228            )229        }230    }231    SubLabel("TEXT SIZE", fg)232    RowLine(fg) {233        Name("Size", fg)234        Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {235            Pill("Default", s.textSize == "medium", fg) { vm.setTextSize("medium") }236            Pill("Large", s.textSize == "large", fg) { vm.setTextSize("large") }237        }238    }239    SubLabel("MOTION", fg)240    RowLine(fg) {241        Name("Reduce motion", fg)242        SubtleButton(if (s.reduceMotion) "On" else "Off", fg) { vm.setReduceMotion(!s.reduceMotion) }243    }244}245246/* ──────────────────────────────  Protection  ─────────────────────────────── */247248@Composable249private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) {250    val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never")251    val current = s.autoLockMinutes ?: 0252253    SubLabel("LOCKING", fg, top = 0.dp)254    RowLine(fg) {255        Name("Auto-lock after", fg)256        val idx = lockOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)257        SubtleButton(lockOptions[idx].second, fg) {258            val next = lockOptions[(idx + 1) % lockOptions.size].first259            vm.setAutoLockMinutes(if (next == 0) 0 else next)260        }261    }262    SubLabel("BIOMETRICS", fg)263    val bioActivity = LocalContext.current as? androidx.fragment.app.FragmentActivity264    RowLine(fg) {265        Name("Unlock with biometrics", fg)266        Toggle(s.biometricsEnabled, fg) { on ->267            if (on && bioActivity != null) vm.enableBiometrics(bioActivity) else vm.disableBiometrics()268        }269    }270    val bioError = com.peachpasswords.ui.lock.Biometrics.statusMessage(LocalContext.current)271    if (bioError != null) {272        Text(273            bioError,274            color = com.peachpasswords.ui.theme.peachColors.Breach,275            fontFamily = PeachType.Mono, fontSize = 10.sp,276            modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 4.dp),277        )278    }279    SubLabel("PASSKEYS", fg)280    RowLine(fg) {281        Column(Modifier.weight(1f)) {282            Text("Credential provider", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)283            Text(284                "Peach can handle passkey sign-in and creation through Android Credential Manager.",285                color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,286                modifier = Modifier.padding(top = 2.dp),287            )288        }289        Toggle(s.passkeyProviderEnabled, fg) { vm.setPasskeyProviderEnabled(it) }290    }291    RowLine(fg) {292        Name("Status", fg)293        ValueText(if (s.passkeyProviderEnabled) "enabled" else "off", fg)294    }295    SubLabel("RECOVERY", fg)296    RowLine(fg) {297        Column(Modifier.weight(1f)) {298            Text("View recovery words", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)299            Text(300                "Keep the paper copy current before rotating sync identity or replacing devices.",301                color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,302                modifier = Modifier.padding(top = 2.dp),303            )304        }305        SubtleButton("view", fg) { onNavigate(PeachNav.RecoveryView) }306    }307    SubLabel("BREACH PROTECTION", fg)308    val checkingBreaches by vm.checkingBreaches.collectAsState()309    val breachResult by vm.breachResult.collectAsState()310    RowLine(fg) {311        Name("Breach monitoring", fg)312        Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }313    }314    RowLine(fg) {315        Name("Check all passwords", fg)316        SubtleButton(if (checkingBreaches) "checking..." else "run", fg) { vm.checkAllBreaches() }317    }318    breachResult?.let { result ->319        RowLine(fg) {320            Name("Last check", fg)321            ValueText(result, fg)322        }323    }324325    SubLabel("MASTER PASSWORD", fg)326    ChangePasswordRow(fg, vm)327328    SubLabel("DURESS PASSWORD", fg)329    val duressIsPro by vm.isPro.collectAsState()330    if (!duressIsPro) {331        RowLine(fg) {332            Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {333                Name("Duress password", fg); ProBadge(fg)334            }335            ValueText("off", fg)336        }337        Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Pro feature.", fg)338    } else {339        DuressSection(fg, vm)340    }341}342343@Composable344private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {345    var open by remember { mutableStateOf(false) }346    var current by remember { mutableStateOf("") }347    var next by remember { mutableStateOf("") }348    var confirm by remember { mutableStateOf("") }349    var error by remember { mutableStateOf<String?>(null) }350    var done by remember { mutableStateOf(false) }351    val scope = rememberCoroutineScope()352353    RowLine(fg) {354        Name("Master password", fg)355        SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }356    }357    AnimatedVisibility(open) {358        Column(Modifier.fillMaxWidth().padding(top = PeachSpacing.sm), verticalArrangement = Arrangement.spacedBy(PeachSpacing.sm)) {359            PwField("current password", current, fg) { current = it }360            PwField("new password (min 12 chars)", next, fg) { next = it }361            PwField("confirm new password", confirm, fg) { confirm = it }362            error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }363            if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)364            SubtleButton("save new password", fg) {365                error = when {366                    current.isBlank() -> "enter your current password"367                    next.length < 12 -> "new password must be at least 12 characters"368                    next != confirm -> "new passwords do not match"369                    next == current -> "new password must differ from current"370                    else -> null371                }372                if (error == null) scope.launch {373                    if (vm.changePassword(current, next)) {374                        current = ""; next = ""; confirm = ""; open = false; done = true375                    } else error = "incorrect current password"376                }377            }378        }379    }380}381382@Composable383private fun PwField(placeholder: String, value: String, @Suppress("UNUSED_PARAMETER") fg: Color, onChange: (String) -> Unit) {384    PeachField(385        label = placeholder,386        value = value,387        onValueChange = onChange,388        keyboardType = androidx.compose.ui.text.input.KeyboardType.Password,389        visualTransformation = PasswordVisualTransformation(),390    )391}392393/* ────────────────────────────────  Vault  ───────────────────────────────── */394395@Composable396private fun VaultBody(397    fg: Color,398    vm: SettingsViewModel,399    s: VaultSettings,400    entriesCount: Int,401    onNavigate: (PeachNav) -> Unit,402) {403    val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")404    val current = s.trashRetentionDays ?: 0405    val isPro by vm.isPro.collectAsState()406    val dedupCount by vm.dedupCount.collectAsState()407    val dedupRunning by vm.dedupRunning.collectAsState()408    val dedupDone by vm.dedupDone.collectAsState()409    val history by vm.vaultHistory.collectAsState()410    val restoringSnapshotId by vm.restoringSnapshotId.collectAsState()411412    SubLabel("ENTRIES", fg, top = 0.dp)413    RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }414    RowLine(fg) {415        Name("Duplicates", fg)416        val done = dedupDone417        if (done != null) {418            ValueText(if (done == 0) "already clean" else "removed $done", com.peachpasswords.ui.theme.peachColors.SyncOk)419        } else {420            val count = dedupCount421            val label = when {422                dedupRunning -> "scanning..."423                count == null -> "scan"424                count == 0 -> "none found"425                else -> "$count found"426            }427            SubtleButton(label, fg) {428                if (count == null || count == 0) vm.scanDuplicates()429            }430        }431    }432    if ((dedupCount ?: 0) > 0 && dedupDone == null) {433        Column(434            Modifier.fillMaxWidth()435                .padding(top = 2.dp, bottom = 8.dp)436                .clip(RoundedCornerShape(8.dp))437                .background(fg.copy(alpha = 0.08f))438                .border(1.dp, fg.copy(alpha = 0.18f), RoundedCornerShape(8.dp))439                .padding(10.dp),440            verticalArrangement = Arrangement.spacedBy(8.dp),441        ) {442            val count = dedupCount ?: 0443            Text(444                "$count duplicate ${if (count == 1) "entry" else "entries"} found. The newest copy of each will be kept; older duplicates will be moved to trash.",445                color = fg.copy(alpha = 0.82f),446                fontFamily = PeachType.Body,447                fontSize = 11.sp,448                lineHeight = 16.sp,449            )450            Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {451                SubtleButton("cancel", fg) { vm.cancelDuplicateRemoval() }452                SubtleButton(if (dedupRunning) "removing..." else "remove duplicates", fg) { vm.removeDuplicates() }453            }454        }455    }456457    SubLabel("MAINTENANCE", fg)458    RowLine(fg) {459        Name("Trash auto-delete", fg)460        val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)461        SubtleButton(trashOptions[idx].second, fg) {462            vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)463        }464    }465    RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }466    RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }467468    SubLabel("DATA", fg)469    RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }470    RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }471    RowLine(fg) {472        Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }473        SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }474    }475    RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }476477    var historyShowAll by remember { mutableStateOf(false) }478    SubLabel("VAULT HISTORY", fg)479    if (history.isEmpty()) {480        Text(481            "No snapshots yet. Peach saves automatically before every change — saves, syncs, and imports.",482            color = fg.copy(alpha = 0.68f),483            fontFamily = PeachType.Body,484            fontSize = 11.sp,485            lineHeight = 16.sp,486            modifier = Modifier.padding(bottom = 6.dp),487        )488    } else {489        Text(490            "Restoring locks your vault. Unlock with the password that encrypted that snapshot to confirm.",491            color = fg.copy(alpha = 0.68f),492            fontFamily = PeachType.Body,493            fontSize = 11.sp,494            lineHeight = 16.sp,495            modifier = Modifier.padding(bottom = 4.dp),496        )497        history.take(if (historyShowAll) history.size else 3).forEach { snap ->498            RowLine(fg) {499                Column(Modifier.weight(1f)) {500                    Text(snapshotTimeLabel(snap.savedAt), color = fg, fontFamily = PeachType.Body, fontSize = 12.sp)501                    Text(snapshotSubLabel(snap), color = fg.copy(alpha = 0.62f), fontFamily = PeachType.Mono, fontSize = 10.sp)502                }503                SubtleButton(if (restoringSnapshotId == snap.id) "..." else "restore", fg) {504                    vm.restoreVaultSnapshot(snap.id)505                }506            }507        }508        if (history.size > 3) {509            RowLine(fg) {510                Name(if (historyShowAll) "show less" else "${history.size - 3} older", fg)511                SubtleButton(if (historyShowAll) "hide" else "show", fg) { historyShowAll = !historyShowAll }512            }513        }514        Text(515            "${history.size} of 5 snapshots",516            color = fg.copy(alpha = 0.58f),517            fontFamily = PeachType.Mono,518            fontSize = 10.sp,519            modifier = Modifier.padding(top = 2.dp, bottom = 6.dp),520        )521    }522523    var advancedOpen by remember { mutableStateOf(false) }524    SubLabel("ADVANCED", fg)525    RowLine(fg) {526        Name("Advanced", fg)527        SubtleButton(if (advancedOpen) "hide" else "show", fg) { advancedOpen = !advancedOpen }528    }529    if (advancedOpen) {530        RowLine(fg) {531            Name("Replace vault from backup", com.peachpasswords.ui.theme.peachColors.SyncBusy)532            SubtleButton("open", com.peachpasswords.ui.theme.peachColors.SyncBusy) { onNavigate(PeachNav.Import) }533        }534        RowLine(fg) {535            Name("Destroy vault", com.peachpasswords.ui.theme.peachColors.Breach)536            SubtleButton("destroy", com.peachpasswords.ui.theme.peachColors.Breach) { onNavigate(PeachNav.Panic) }537        }538    }539}540541private fun snapshotSubLabel(snapshot: VaultSnapshot): String {542    val count = snapshot.entryCount?.let { "up to $it ${if (it == 1) "entry" else "entries"}" }543    return listOfNotNull(count, snapshotReasonLabel(snapshot.reason)).joinToString(" · ")544}545546private fun snapshotReasonLabel(reason: String): String = when (reason) {547    "local_save" -> "saved"548    "sync_received" -> "synced"549    "import" -> "imported"550    "restore" -> "restored"551    else -> reason552}553554private fun snapshotTimeLabel(savedAt: Long): String {555    val diff = System.currentTimeMillis() - savedAt556    if (diff < 60_000) return "Just now"557    if (diff < 3_600_000) return "${diff / 60_000}m ago"558    val date = Date(savedAt)559    val today = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date())560    val thenDay = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(date)561    val time = SimpleDateFormat("h:mm a", Locale.getDefault()).format(date)562    if (today == thenDay) return "Today $time"563    val yesterday = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date(System.currentTimeMillis() - 86_400_000))564    if (yesterday == thenDay) return "Yesterday $time"565    return SimpleDateFormat("MMM d h:mm a", Locale.getDefault()).format(date)566}567568/* ────────────────────────────────  Sync  ────────────────────────────────── */569570@Composable571private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {572    val syncVm: SyncViewModel = hiltViewModel()573    val pairedDevices by syncVm.pairedDevices.collectAsState()574    val pendingVouched by syncVm.pendingVouched.collectAsState()575    val syncStatus by syncVm.status.collectAsState()576    val scope = rememberCoroutineScope()577    var confirmUnpair by remember { mutableStateOf<String?>(null) }578    var rotateConfirmOpen by remember { mutableStateOf(false) }579    var rotating by remember { mutableStateOf(false) }580    var rotateError by remember { mutableStateOf<String?>(null) }581582    SubLabel("PAIRING", fg, top = 0.dp)583    RowLine(fg) {584        Column(Modifier.weight(1f)) {585            Row(verticalAlignment = Alignment.CenterVertically) {586                Text("Peach Sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp); ProBadge(fg)587            }588            Text(589                "Pair nearby devices by chirp and keep encrypted vault blobs in step without a central account.",590                color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,591                modifier = Modifier.padding(top = 2.dp),592            )593        }594    }595    // The whole row is the tap target — no separate "open" button (browser596    // sync-hub parity: every settings row is tappable, the chevron signals it).597    RowLine(fg, Modifier.clickable { onNavigate(PeachNav.ChirpPair) }) {598        Name("Sync hub", fg)599        Text("›", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 15.sp)600    }601    RowLine(fg) {602        Column(Modifier.weight(1f)) {603            Text("Pair new device", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)604            Text(605                "Add a phone, another browser, or your desktop sync helper.",606                color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,607                modifier = Modifier.padding(top = 2.dp),608            )609        }610        SubtleButton("pair", fg) { onNavigate(PeachNav.ChirpPair) }611    }612613    SubLabel("PAIRED DEVICES", fg)614    if (pairedDevices.isEmpty()) {615        PeachEmptyOrEndState(616            message = "No paired devices yet.",617            detail = "Pair a nearby phone, browser, or desktop helper when you're ready to sync.",618            modifier = Modifier.padding(top = PeachSpacing.xs),619        )620    } else {621        pairedDevices.forEach { d ->622            RowLine(fg) {623                Column(Modifier.weight(1f)) {624                    Text(d.deviceName ?: d.deviceId, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)625                    Text(626                        "${deviceTypeLabel(d.deviceType)} · ${syncTimeLabel(d.lastSyncedAt)}${if (isSyncStale(d.lastSyncedAt)) " · not seen recently" else ""}",627                        color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,628                        modifier = Modifier.padding(top = 2.dp),629                    )630                }631                if (confirmUnpair == d.deviceId) {632                    Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {633                        SubtleButton("cancel", fg) { confirmUnpair = null }634                        SubtleButton("remove", peachColors.Breach) { syncVm.unpairDevice(d.deviceId); confirmUnpair = null }635                    }636                } else {637                    SubtleButton("remove", fg) { confirmUnpair = d.deviceId }638                }639            }640        }641        RowLine(fg) {642            ValueText(syncFlashLabel(syncStatus), fg)643            SubtleButton(if (syncStatus == SyncStatus.Syncing) "syncing..." else "sync now", fg) {644                if (syncStatus != SyncStatus.Syncing) syncVm.syncNow()645            }646        }647    }648649    if (pendingVouched.isNotEmpty()) {650        SubLabel("PENDING DEVICES", fg)651        pendingVouched.forEach { dev ->652            RowLine(fg) {653                Column(Modifier.weight(1f)) {654                    Text(dev.deviceName, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)655                    Text(656                        "Was added by another of your devices. Allow it to sync with this vault?",657                        color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,658                        modifier = Modifier.padding(top = 2.dp),659                    )660                }661                Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {662                    SubtleButton("Allow", fg) { syncVm.confirmVouchedDevice(dev.deviceId) }663                    SubtleButton("Reject", fg) { syncVm.rejectVouchedDevice(dev.deviceId) }664                }665            }666        }667    }668669    SubLabel("RECOVERY", fg)670    if (rotateConfirmOpen) {671        Hint("This will disconnect all paired devices and your 12 recovery words will change. You'll be shown the new words next.", peachColors.Breach)672        rotateError?.let {673            Text(it, color = peachColors.Breach, fontFamily = PeachType.Body, fontSize = 11.sp, modifier = Modifier.padding(top = 6.dp))674        }675        Row(Modifier.padding(top = 10.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {676            SubtleButton("cancel", fg) { if (!rotating) rotateConfirmOpen = false }677            SubtleButton(if (rotating) "rotating..." else "Rotate sync identity", peachColors.Breach) {678                if (rotating) return@SubtleButton679                rotating = true680                rotateError = null681                scope.launch {682                    val ok = syncVm.rotateSyncIdentity()683                    rotating = false684                    if (ok) {685                        rotateConfirmOpen = false686                        onNavigate(PeachNav.RecoverySetup)687                    } else {688                        rotateError = "Rotation failed. Unlock your real vault and try again."689                    }690                }691            }692        }693    } else {694        RowLine(fg) {695            Column(Modifier.weight(1f)) {696                Text("Rotate sync identity", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)697                Text(698                    "Use this if a paired device was lost or stolen. Re-keys the vault so the old device's key is useless.",699                    color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,700                    modifier = Modifier.padding(top = 2.dp),701                )702            }703            SubtleButton("rotate", peachColors.Breach) { rotateError = null; rotateConfirmOpen = true }704        }705    }706707    Hint("Sync uses the same zero-knowledge vault format as backup and restore; pairing authorizes a device, not a cloud account.", fg)708}709710private fun deviceTypeLabel(type: String?): String = when (type) {711    "android" -> "Android"712    "phone" -> "Phone"713    "tablet" -> "Tablet"714    "desktop" -> "Desktop"715    "browser" -> "Browser"716    else -> "Device"717}718719private fun syncTimeLabel(lastSyncedAt: Long?): String {720    if (lastSyncedAt == null) return "never synced"721    val diff = System.currentTimeMillis() - lastSyncedAt722    if (diff < 60_000) return "just now"723    if (diff < 3_600_000) return "${diff / 60_000}m ago"724    if (diff < 86_400_000) return "${diff / 3_600_000}h ago"725    return "${diff / 86_400_000}d ago"726}727728private fun isSyncStale(lastSyncedAt: Long?): Boolean =729    lastSyncedAt != null && System.currentTimeMillis() - lastSyncedAt > 7L * 24L * 60L * 60L * 1000L730731private fun syncFlashLabel(status: SyncStatus): String = when (status) {732    SyncStatus.Idle -> ""733    SyncStatus.Syncing -> "syncing..."734    SyncStatus.Offline -> "offline"735    is SyncStatus.Error -> status.message736    is SyncStatus.LastSynced -> "synced ${syncTimeLabel(status.timestamp)}"737}738739/* ──────────────────────────────  Shortcuts  ──────────────────────────────── */740741@Composable742private fun ShortcutsBody(fg: Color) {743    val bindings = listOf(744        "Copy password" to "⌘C", "Copy username" to "⌘⇧C", "Open entry" to "↵",745        "Edit entry" to "E", "New entry" to "⌘N", "Search" to "/",746    )747    SubLabel("KEYBINDINGS", fg, top = 0.dp)748    Hint("Shortcuts apply when a hardware keyboard is attached. Defaults shown below.", fg)749    Spacer(Modifier.height(8.dp))750    bindings.forEach { (label, key) ->751        RowLine(fg) {752            Name(label, fg)753            Box(754                Modifier.clip(RoundedCornerShape(4.dp)).background(fg.copy(alpha = 0.06f))755                    .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(4.dp))756                    .padding(horizontal = 7.dp, vertical = 2.dp),757            ) { Text(key, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp) }758        }759    }760}761762/* ────────────────────────────────  Pro  ─────────────────────────────────── */763764@Composable765private fun ProBody(fg: Color, vm: SettingsViewModel) {766    val ctx = LocalContext.current767    val isPro by vm.isPro.collectAsState()768    if (isPro) {769        ProActiveBody(fg, vm)770        return771    }772    val features = listOf(773        "Peach Sync" to "Encrypted · peer-to-peer",774        "Peach Codex" to "Restore from paper",775        "Passkeys" to "Zero-knowledge WebAuthn",776        "Advanced Vault Health" to "Reuse · age · exposure",777        "Canary entries" to "Detects vault compromise",778        "Duress vault" to "Decoy under coercion",779    )780    Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)781    Text(782        "Everything, everywhere.",783        modifier = Modifier.padding(top = 8.dp),784        color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,785    )786    Text(787        "One key unlocks every Pro feature — for the lifetime of the app.",788        modifier = Modifier.padding(top = 6.dp),789        color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,790    )791    Spacer(Modifier.height(12.dp))792    features.forEachIndexed { i, (name, desc) ->793        RowLine(fg) {794            Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {795                Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))796                Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)797            }798            Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)799        }800    }801    Spacer(Modifier.height(14.dp))802    Text(803        "$39",804        color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,805    )806    Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)807    Spacer(Modifier.height(10.dp))808    Box(809        Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))810            .background(fg.copy(alpha = 0.16f))811            .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))812            .clickable {813                runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }814            }815            .padding(vertical = 12.dp),816        contentAlignment = Alignment.Center,817    ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }818819    Spacer(Modifier.height(16.dp))820    Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)821    var key by remember { mutableStateOf("") }822    val activating by vm.activating.collectAsState()823    val activationError by vm.activationError.collectAsState()824    Box(825        Modifier.fillMaxWidth().padding(top = 6.dp)826            .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))827            .padding(horizontal = 12.dp, vertical = 10.dp),828    ) {829        BasicTextField(830            value = key,831            // NOT .uppercase() — base58 (the license payload encoding) is832            // case-sensitive; forcing the whole string to uppercase silently833            // corrupted every real key before it ever reached signature834            // verification, so activation always failed with a real key.835            onValueChange = { key = it; vm.clearActivationError() },836            singleLine = true,837            textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),838            cursorBrush = SolidColor(fg),839            modifier = Modifier.fillMaxWidth(),840            decorationBox = { inner ->841                if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)842                inner()843            },844        )845    }846    if (activationError != null) {847        Text(activationError!!, color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))848    }849    Spacer(Modifier.height(8.dp))850    Box(851        Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))852            .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))853            .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))854            .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }855            .padding(vertical = 12.dp),856        contentAlignment = Alignment.Center,857    ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }858}859860@Composable861private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {862    val ctx = LocalContext.current863    val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")864    val licenseKey by vm.licenseKey.collectAsState()865    val issuedAt by vm.licenseIssuedAt.collectAsState()866    var showKey by remember { mutableStateOf(false) }867    var copied by remember { mutableStateOf(false) }868    val scope = rememberCoroutineScope()869    Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {870        com.peachpasswords.ui.components.PeachMark(size = 60.dp)871    }872    Text(873        "Peach Pro",874        modifier = Modifier.fillMaxWidth(),875        color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,876        textAlign = androidx.compose.ui.text.style.TextAlign.Center,877    )878    Text(879        formatLicenseActiveSince(issuedAt),880        modifier = Modifier.fillMaxWidth().padding(top = 4.dp),881        color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,882        textAlign = androidx.compose.ui.text.style.TextAlign.Center,883    )884    licenseKey?.let { key ->885        Spacer(Modifier.height(12.dp))886        Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)887        RowLine(fg) {888            Text(889                if (showKey) key else "************************",890                color = fg.copy(alpha = if (showKey) 0.82f else 0.58f),891                fontFamily = PeachType.Mono,892                fontSize = 10.sp,893                modifier = Modifier.weight(1f),894            )895            Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {896                SubtleButton(if (copied) "copied" else "copy", fg) {897                    PeachClipboard.copy(ctx, "peach license", key)898                    copied = true899                    scope.launch {900                        delay(1_500)901                        copied = false902                    }903                }904                SubtleButton(if (showKey) "hide" else "reveal", fg) { showKey = !showKey }905            }906        }907    }908    Spacer(Modifier.height(12.dp))909    features.forEachIndexed { i, name ->910        RowLine(fg) {911            Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {912                Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))913                Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)914            }915            Text("unlocked", color = com.peachpasswords.ui.theme.peachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)916        }917    }918    Spacer(Modifier.height(12.dp))919    Box(920        Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))921            .border(1.dp, com.peachpasswords.ui.theme.peachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))922            .clickable { vm.deactivate() }923            .padding(vertical = 12.dp),924        contentAlignment = Alignment.Center,925    ) { Text("Deactivate", color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }926}927928private fun formatLicenseActiveSince(issuedAt: Long?): String {929    if (issuedAt == null) return "Active"930    val monthYear = SimpleDateFormat("MMMM yyyy", Locale.getDefault()).format(Date(issuedAt))931    return "Active since $monthYear"932}933934/* ──────────────────────────────  Feedback  ───────────────────────────────── */935936@OptIn(ExperimentalLayoutApi::class)937@Composable938private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {939    val categories = listOf("Bug report", "Feature request", "Question", "Other")940    var category by remember { mutableStateOf(categories[0]) }941    var message by remember { mutableStateOf("") }942    val state by vm.feedbackState.collectAsState()943944    // Reset transient state when the card leaves composition so reopening starts fresh.945    DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }946947    if (state is FeedbackState.Sent) {948        Box(949            Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))950                .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),951        ) {952            Column {953                Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)954                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))955            }956        }957        return958    }959960    val sending = state is FeedbackState.Sending961962    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)963    SubLabel("TYPE", fg)964    FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {965        categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }966    }967    SubLabel("MESSAGE", fg)968    Box(969        Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))970            .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))971            .padding(10.dp),972    ) {973        if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)974        BasicTextField(975            value = message, onValueChange = { message = it.take(MAX_FEEDBACK_MESSAGE_LENGTH) },976            enabled = !sending,977            textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),978            cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),979        )980    }981    Text(982        "Version ${BuildConfig.VERSION_NAME} · will be included automatically",983        modifier = Modifier.padding(top = 6.dp),984        color = fg.copy(alpha = 0.52f),985        fontFamily = PeachType.Mono,986        fontSize = 10.sp,987        lineHeight = 14.sp,988    )989    Spacer(Modifier.height(8.dp))990991    Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {992        val canSend = !sending && sanitizeFeedbackMessage(message).isNotBlank()993        Box(994            Modifier.clip(RoundedCornerShape(8.dp))995                .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))996                .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))997                .clickable(enabled = canSend) { vm.sendFeedback(category, message) }998                .padding(horizontal = 12.dp, vertical = 6.dp),999        ) {1000            Text(1001                feedbackSubmitLabel(state),1002                color = fg.copy(alpha = if (canSend) 1f else 0.4f),1003                fontFamily = PeachType.Mono, fontSize = 11.sp,1004            )1005        }1006        if (sending) {1007            CircularProgressIndicator(1008                color = LocalPeachAccent.current,1009                strokeWidth = 2.dp,1010                modifier = Modifier.size(16.dp),1011            )1012        }1013    }10141015    (state as? FeedbackState.Error)?.let { err ->1016        Text(1017            err.message,1018            modifier = Modifier.padding(top = 8.dp),1019            color = peachColors.Breach,1020            fontFamily = PeachType.Mono,1021            fontSize = 11.sp,1022            lineHeight = 15.sp,1023        )1024    }10251026    Hint("Sent anonymously · no account required", fg)1027}10281029/* ──────────────────────────────  D13 Duress  ─────────────────────────────── */10301031@Composable1032internal fun DuressSection(fg: Color, vm: SettingsViewModel) {1033    val configured by vm.duressConfigured.collectAsState()1034    if (configured) DuressActiveState(fg, vm) else DuressForm(fg, vm)1035}10361037@Composable1038private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {1039    Text(1040        "Duress password is active",1041        color = peachColors.HealthOk,1042        fontFamily = PeachType.Mono,1043        fontSize = 11.sp,1044        modifier = Modifier.padding(top = 6.dp),1045    )1046    Spacer(Modifier.height(8.dp))1047    DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }1048    Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)1049}10501051@Composable1052private fun DuressForm(fg: Color, vm: SettingsViewModel) {1053    var enabled by remember { mutableStateOf(false) }1054    var password by remember { mutableStateOf("") }1055    var confirm by remember { mutableStateOf("") }1056    var action by remember { mutableStateOf(DuressAction.DECOY) }1057    var error by remember { mutableStateOf<String?>(null) }1058    val scope = rememberCoroutineScope()10591060    RowLine(fg) {1061        Name("Duress password", fg)1062        Toggle(enabled, fg) { on ->1063            enabled = on1064            if (!on) { password = ""; confirm = ""; error = null }1065        }1066    }1067    Text(1068        "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",1069        color = fg.copy(alpha = 0.7f),1070        fontFamily = PeachType.Mono,1071        fontSize = 10.sp,1072        modifier = Modifier.padding(top = 6.dp),1073    )10741075    AnimatedVisibility(enabled) {1076        Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1077            PwField("DURESS PASSPHRASE", password, fg) { password = it; error = null }1078            PwField("CONFIRM DURESS PASSPHRASE", confirm, fg) { confirm = it; error = null }10791080            Text(1081                "When your duress password is entered at the lock screen, Peach will:",1082                color = fg.copy(alpha = 0.7f),1083                fontFamily = PeachType.Mono,1084                fontSize = 10.sp,1085                modifier = Modifier.padding(top = 4.dp),1086            )10871088            DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }1089            DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }10901091            error?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }10921093            val canSave = password.isNotBlank() && confirm.isNotBlank()1094            DuressSaveButton("Save duress password", fg, canSave) {1095                error = when {1096                    password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"1097                    password != confirm -> "Passwords do not match"1098                    else -> null1099                }1100                if (error == null) scope.launch {1101                    if (vm.saveDuress(password, action)) {1102                        password = ""; confirm = ""; enabled = false1103                    } else {1104                        error = "Couldn't save — the duress passphrase must differ from your real password"1105                    }1106                }1107            }1108        }1109    }1110}11111112@Composable1113private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {1114    val accent = LocalPeachAccent.current1115    Row(1116        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),1117        verticalAlignment = Alignment.CenterVertically,1118        horizontalArrangement = Arrangement.spacedBy(10.dp),1119    ) {1120        Box(1121            Modifier.size(16.dp).clip(CircleShape)1122                .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),1123            contentAlignment = Alignment.Center,1124        ) {1125            if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))1126        }1127        Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)1128    }1129}11301131@Composable1132private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {1133    val accent = LocalPeachAccent.current1134    val tint = if (enabled) accent else fg.copy(alpha = 0.3f)1135    Box(1136        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1137            .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))1138            .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))1139            .let { if (enabled) it.clickable(onClick = onClick) else it }1140            .padding(vertical = 11.dp),1141        contentAlignment = Alignment.Center,1142    ) {1143        Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)1144    }1145}11461147@Composable1148private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {1149    Box(1150        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1151            .border(1.dp, peachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))1152            .clickable(onClick = onClick)1153            .padding(vertical = 11.dp),1154        contentAlignment = Alignment.Center,1155    ) {1156        Text(label, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)1157    }1158}