SettingsCardBodies.kt

29.2 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.ui.theme.PeachColors34import androidx.compose.runtime.mutableStateOf35import androidx.compose.runtime.remember36import androidx.compose.runtime.rememberCoroutineScope37import androidx.compose.runtime.setValue38import androidx.compose.ui.Alignment39import androidx.compose.ui.Modifier40import androidx.compose.ui.draw.clip41import androidx.compose.ui.graphics.Color42import androidx.compose.ui.graphics.SolidColor43import androidx.compose.ui.platform.LocalContext44import androidx.compose.ui.text.TextStyle45import androidx.compose.ui.text.font.FontStyle46import androidx.compose.ui.text.input.PasswordVisualTransformation47import androidx.compose.ui.unit.Dp48import androidx.compose.ui.unit.dp49import androidx.compose.ui.unit.em50import androidx.compose.ui.unit.sp51import androidx.compose.material3.Text52import com.peachpasswords.ui.PeachNav53import com.peachpasswords.ui.theme.ACCENT_COLORS54import com.peachpasswords.ui.theme.PeachType55import com.peachpasswords.vault.VaultSettings56import kotlinx.coroutines.launch5758private const val PRO_URL = "https://buy.polar.sh/polar_cl_IXSFIPojx67rcOTksn8LkH5mnU3osPHtYqBIl1eyuIz"5960/**61 * Body content for the active stack card. Everything is tinted with the card's62 * own foreground [fg] (the browser's `currentColor` convention), so each card's63 * rows inherit its palette. Rows whose backend doesn't exist yet (duress,64 * canary, license activation) render their browser visual but defer the action65 * to a later phase — noted inline where that's the case.66 */67@Composable68fun CardBody(69    id: CardId,70    fg: Color,71    vm: SettingsViewModel,72    settings: VaultSettings,73    entriesCount: Int,74    onNavigate: (PeachNav) -> Unit,75) {76    when (id) {77        CardId.Appearance -> AppearanceBody(fg, vm, settings)78        CardId.Protection -> ProtectionBody(fg, vm, settings, onNavigate)79        CardId.Vault -> VaultBody(fg, vm, settings, entriesCount, onNavigate)80        CardId.Sync -> SyncBody(fg, onNavigate)81        CardId.Shortcuts -> ShortcutsBody(fg)82        CardId.Pro -> ProBody(fg, vm)83        CardId.Feedback -> FeedbackBody(fg, vm)84    }85}8687/* ─────────────────────────  shared row vocabulary  ───────────────────────── */8889@Composable90private fun SubLabel(text: String, fg: Color, top: Dp = 14.dp) {91    Text(92        text,93        modifier = Modifier.padding(top = top, bottom = 4.dp),94        color = fg.copy(alpha = 0.58f),95        fontFamily = PeachType.Mono,96        fontSize = 8.sp,97        letterSpacing = 0.22.em,98    )99}100101@Composable102private fun RowLine(fg: Color, content: @Composable RowScope.() -> Unit) {103    Row(104        Modifier.fillMaxWidth().padding(vertical = 9.dp),105        verticalAlignment = Alignment.CenterVertically,106        horizontalArrangement = Arrangement.SpaceBetween,107        content = content,108    )109    Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.12f)))110}111112@Composable113private fun RowScope.Name(text: String, fg: Color) {114    Text(text, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp, modifier = Modifier.weight(1f))115}116117@Composable118private fun ValueText(text: String, fg: Color) {119    Text(text, color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Mono, fontSize = 11.sp)120}121122@Composable123private fun SubtleButton(label: String, fg: Color, onClick: () -> Unit) {124    Box(125        Modifier.clip(RoundedCornerShape(8.dp))126            .border(1.dp, fg.copy(alpha = 0.28f), RoundedCornerShape(8.dp))127            .background(fg.copy(alpha = 0.08f))128            .clickable(onClick = onClick)129            .padding(horizontal = 12.dp, vertical = 6.dp),130    ) {131        Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp)132    }133}134135@Composable136private fun Toggle(on: Boolean, fg: Color, onToggle: (Boolean) -> Unit) {137    val knob by animateDpAsState(if (on) 16.dp else 2.dp, label = "knob")138    Box(139        Modifier.size(width = 34.dp, height = 20.dp).clip(RoundedCornerShape(999.dp))140            .background(if (on) fg.copy(alpha = 0.28f) else fg.copy(alpha = 0.08f))141            .border(1.dp, fg.copy(alpha = if (on) 0.5f else 0.32f), RoundedCornerShape(999.dp))142            .clickable { onToggle(!on) },143    ) {144        Box(145            Modifier.padding(top = 2.dp).width(16.dp).fillMaxWidth().height(16.dp)146                .padding(start = knob - 2.dp)147                .size(14.dp).clip(CircleShape)148                .background(if (on) fg else fg.copy(alpha = 0.58f)),149        )150    }151}152153@Composable154private fun Pill(label: String, active: Boolean, fg: Color, onClick: () -> Unit) {155    Box(156        Modifier.clip(RoundedCornerShape(999.dp))157            .border(1.dp, fg.copy(alpha = if (active) 0.55f else 0.32f), RoundedCornerShape(999.dp))158            .background(if (active) fg.copy(alpha = 0.18f) else Color.Transparent)159            .clickable(onClick = onClick)160            .padding(horizontal = 12.dp, vertical = 5.dp),161    ) {162        Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)163    }164}165166@Composable167private fun ProBadge(fg: Color) {168    Box(169        Modifier.padding(start = 6.dp).clip(RoundedCornerShape(4.dp))170            .background(fg.copy(alpha = 0.16f)).padding(horizontal = 5.dp, vertical = 1.dp),171    ) {172        Text("Pro", color = fg.copy(alpha = 0.85f), fontFamily = PeachType.Mono, fontSize = 8.sp)173    }174}175176@Composable177private fun Hint(text: String, fg: Color) {178    Text(179        text,180        modifier = Modifier.padding(top = 6.dp),181        color = fg.copy(alpha = 0.6f),182        fontFamily = PeachType.Display,183        fontStyle = FontStyle.Italic,184        fontSize = 11.5.sp,185        lineHeight = 16.sp,186    )187}188189/* ──────────────────────────────  Appearance  ─────────────────────────────── */190191@OptIn(ExperimentalLayoutApi::class)192@Composable193private fun AppearanceBody(fg: Color, vm: SettingsViewModel, s: VaultSettings) {194    SubLabel("THEME", fg, top = 0.dp)195    RowLine(fg) {196        Name("Theme", fg)197        SubtleButton(if (s.theme == "dark") "Switch to light" else "Switch to dark", fg) {198            vm.setTheme(if (s.theme == "dark") "light" else "dark")199        }200    }201    SubLabel("ACCENT", fg)202    FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {203        ACCENT_COLORS.forEach { (name, color) ->204            Box(205                Modifier.size(22.dp).clip(CircleShape).background(color)206                    .border(207                        if (s.accentColor == name) 2.dp else 1.dp,208                        if (s.accentColor == name) fg else fg.copy(alpha = 0.2f),209                        CircleShape,210                    )211                    .clickable { vm.setAccent(name) },212            )213        }214    }215    SubLabel("TEXT SIZE", fg)216    RowLine(fg) {217        Name("Size", fg)218        Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {219            Pill("Default", s.textSize == "medium", fg) { vm.setTextSize("medium") }220            Pill("Large", s.textSize == "large", fg) { vm.setTextSize("large") }221        }222    }223    SubLabel("MOTION", fg)224    RowLine(fg) {225        Name("Reduce motion", fg)226        SubtleButton(if (s.reduceMotion) "On" else "Off", fg) { vm.setReduceMotion(!s.reduceMotion) }227    }228}229230/* ──────────────────────────────  Protection  ─────────────────────────────── */231232@Composable233private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) {234    val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never")235    val current = s.autoLockMinutes ?: 0236237    SubLabel("LOCKING", fg, top = 0.dp)238    RowLine(fg) {239        Name("Auto-lock after", fg)240        val idx = lockOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)241        SubtleButton(lockOptions[idx].second, fg) {242            val next = lockOptions[(idx + 1) % lockOptions.size].first243            vm.setAutoLockMinutes(if (next == 0) 0 else next)244        }245    }246    SubLabel("BIOMETRICS", fg)247    val bioActivity = LocalContext.current as? androidx.fragment.app.FragmentActivity248    RowLine(fg) {249        Name("Unlock with biometrics", fg)250        Toggle(s.biometricsEnabled, fg) { on ->251            if (on && bioActivity != null) vm.enableBiometrics(bioActivity) else vm.disableBiometrics()252        }253    }254    val bioError = com.peachpasswords.ui.lock.Biometrics.statusMessage(LocalContext.current)255    if (bioError != null) {256        Text(257            bioError,258            color = com.peachpasswords.ui.theme.PeachColors.Breach,259            fontFamily = PeachType.Mono, fontSize = 10.sp,260            modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 4.dp),261        )262    }263    SubLabel("RECOVERY", fg)264    RowLine(fg) {265        Name("View recovery words", fg)266        SubtleButton("view", fg) { onNavigate(PeachNav.RecoveryView) }267    }268    SubLabel("BREACH PROTECTION", fg)269    RowLine(fg) {270        Name("Breach monitoring", fg)271        Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }272    }273274    SubLabel("MASTER PASSWORD", fg)275    ChangePasswordRow(fg, vm)276277    SubLabel("DURESS PASSWORD", fg)278    RowLine(fg) {279        Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {280            Name("Duress password", fg); ProBadge(fg)281        }282        ValueText("off", fg)283    }284    Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Arrives with Pro sync.", fg)285}286287@Composable288private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {289    var open by remember { mutableStateOf(false) }290    var current by remember { mutableStateOf("") }291    var next by remember { mutableStateOf("") }292    var confirm by remember { mutableStateOf("") }293    var error by remember { mutableStateOf<String?>(null) }294    var done by remember { mutableStateOf(false) }295    val scope = rememberCoroutineScope()296297    RowLine(fg) {298        Name("Master password", fg)299        SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }300    }301    AnimatedVisibility(open) {302        Column(Modifier.fillMaxWidth().padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {303            PwField("current password", current, fg) { current = it }304            PwField("new password (min 12 chars)", next, fg) { next = it }305            PwField("confirm new password", confirm, fg) { confirm = it }306            error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }307            if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)308            SubtleButton("save new password", fg) {309                error = when {310                    current.isBlank() -> "enter your current password"311                    next.length < 12 -> "new password must be at least 12 characters"312                    next != confirm -> "new passwords do not match"313                    next == current -> "new password must differ from current"314                    else -> null315                }316                if (error == null) scope.launch {317                    if (vm.changePassword(current, next)) {318                        current = ""; next = ""; confirm = ""; open = false; done = true319                    } else error = "incorrect current password"320                }321            }322        }323    }324}325326@Composable327private fun PwField(placeholder: String, value: String, fg: Color, onChange: (String) -> Unit) {328    Box(329        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))330            .background(Color(0x2E000000))331            .border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))332            .padding(horizontal = 10.dp, vertical = 10.dp),333    ) {334        if (value.isEmpty()) {335            Text(placeholder, color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Mono, fontSize = 12.sp)336        }337        BasicTextField(338            value = value,339            onValueChange = onChange,340            singleLine = true,341            textStyle = TextStyle(color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp),342            cursorBrush = SolidColor(fg),343            visualTransformation = PasswordVisualTransformation(),344            modifier = Modifier.fillMaxWidth(),345        )346    }347}348349/* ────────────────────────────────  Vault  ───────────────────────────────── */350351@Composable352private fun VaultBody(353    fg: Color,354    vm: SettingsViewModel,355    s: VaultSettings,356    entriesCount: Int,357    onNavigate: (PeachNav) -> Unit,358) {359    val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")360    val current = s.trashRetentionDays ?: 0361    val isPro by vm.isPro.collectAsState()362363    SubLabel("ENTRIES", fg, top = 0.dp)364    RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }365366    SubLabel("MAINTENANCE", fg)367    RowLine(fg) {368        Name("Trash auto-delete", fg)369        val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)370        SubtleButton(trashOptions[idx].second, fg) {371            vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)372        }373    }374    RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }375    RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }376377    SubLabel("DATA", fg)378    RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }379    RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }380    RowLine(fg) {381        Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }382        SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }383    }384    RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }385386    var advancedOpen by remember { mutableStateOf(false) }387    SubLabel("ADVANCED", fg)388    RowLine(fg) {389        Name("Advanced", fg)390        SubtleButton(if (advancedOpen) "hide" else "show", fg) { advancedOpen = !advancedOpen }391    }392    if (advancedOpen) {393        RowLine(fg) {394            Name("Replace vault from backup", com.peachpasswords.ui.theme.PeachColors.SyncBusy)395            SubtleButton("open", com.peachpasswords.ui.theme.PeachColors.SyncBusy) { onNavigate(PeachNav.Import) }396        }397        RowLine(fg) {398            Name("Destroy vault", com.peachpasswords.ui.theme.PeachColors.Breach)399            SubtleButton("destroy", com.peachpasswords.ui.theme.PeachColors.Breach) { onNavigate(PeachNav.Panic) }400        }401    }402}403404/* ────────────────────────────────  Sync  ────────────────────────────────── */405406@Composable407private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {408    SubLabel("PAIRING", fg, top = 0.dp)409    RowLine(fg) {410        Column(Modifier.weight(1f)) {411            Row(verticalAlignment = Alignment.CenterVertically) {412                Text("Peach Sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp); ProBadge(fg)413            }414            Text(415                "Pair nearby devices by chirp and keep encrypted vault blobs in step without a central account.",416                color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,417                modifier = Modifier.padding(top = 2.dp),418            )419        }420    }421    RowLine(fg) { Name("Status", fg); ValueText("Requires Pro", fg) }422    RowLine(fg) { Name("Sync hub", fg); SubtleButton("open", fg) { onNavigate(PeachNav.ChirpPair) } }423424    SubLabel("DEVICE FLOW", fg)425    RowLine(fg) { Name("Pair new device", fg); SubtleButton("pair", fg) { onNavigate(PeachNav.ChirpPair) } }426    Hint("Sync uses the same zero-knowledge vault format as backup and restore; pairing authorizes a device, not a cloud account.", fg)427}428429/* ──────────────────────────────  Shortcuts  ──────────────────────────────── */430431@Composable432private fun ShortcutsBody(fg: Color) {433    val bindings = listOf(434        "Copy password" to "⌘C", "Copy username" to "⌘⇧C", "Open entry" to "↵",435        "Edit entry" to "E", "New entry" to "⌘N", "Search" to "/",436    )437    SubLabel("KEYBINDINGS", fg, top = 0.dp)438    Hint("Shortcuts apply when a hardware keyboard is attached. Defaults shown below.", fg)439    Spacer(Modifier.height(8.dp))440    bindings.forEach { (label, key) ->441        RowLine(fg) {442            Name(label, fg)443            Box(444                Modifier.clip(RoundedCornerShape(4.dp)).background(fg.copy(alpha = 0.06f))445                    .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(4.dp))446                    .padding(horizontal = 7.dp, vertical = 2.dp),447            ) { Text(key, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp) }448        }449    }450}451452/* ────────────────────────────────  Pro  ─────────────────────────────────── */453454@Composable455private fun ProBody(fg: Color, vm: SettingsViewModel) {456    val ctx = LocalContext.current457    val isPro by vm.isPro.collectAsState()458    if (isPro) {459        ProActiveBody(fg, vm)460        return461    }462    val features = listOf(463        "Peach Sync" to "Encrypted · peer-to-peer",464        "Peach Codex" to "Restore from paper",465        "Passkeys" to "Zero-knowledge WebAuthn",466        "Advanced Vault Health" to "Reuse · age · exposure",467        "Canary entries" to "Detects vault compromise",468        "Duress vault" to "Decoy under coercion",469    )470    Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)471    Text(472        "Everything, everywhere.",473        modifier = Modifier.padding(top = 8.dp),474        color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,475    )476    Text(477        "One key unlocks every Pro feature — for the lifetime of the app.",478        modifier = Modifier.padding(top = 6.dp),479        color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,480    )481    Spacer(Modifier.height(12.dp))482    features.forEachIndexed { i, (name, desc) ->483        RowLine(fg) {484            Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {485                Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))486                Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)487            }488            Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)489        }490    }491    Spacer(Modifier.height(14.dp))492    Text(493        "$39",494        color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,495    )496    Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)497    Spacer(Modifier.height(10.dp))498    Box(499        Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))500            .background(fg.copy(alpha = 0.16f))501            .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))502            .clickable {503                runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }504            }505            .padding(vertical = 12.dp),506        contentAlignment = Alignment.Center,507    ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }508509    Spacer(Modifier.height(16.dp))510    Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)511    var key by remember { mutableStateOf("") }512    val activating by vm.activating.collectAsState()513    val activationError by vm.activationError.collectAsState()514    Box(515        Modifier.fillMaxWidth().padding(top = 6.dp)516            .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))517            .padding(horizontal = 12.dp, vertical = 10.dp),518    ) {519        BasicTextField(520            value = key,521            onValueChange = { key = it.uppercase(); vm.clearActivationError() },522            singleLine = true,523            textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),524            cursorBrush = SolidColor(fg),525            modifier = Modifier.fillMaxWidth(),526            decorationBox = { inner ->527                if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)528                inner()529            },530        )531    }532    if (activationError != null) {533        Text(activationError!!, color = com.peachpasswords.ui.theme.PeachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))534    }535    Spacer(Modifier.height(8.dp))536    Box(537        Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))538            .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))539            .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))540            .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }541            .padding(vertical = 12.dp),542        contentAlignment = Alignment.Center,543    ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }544}545546@Composable547private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {548    val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")549    Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {550        com.peachpasswords.ui.components.PeachMark(size = 60.dp)551    }552    Text(553        "Peach Pro",554        modifier = Modifier.fillMaxWidth(),555        color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,556        textAlign = androidx.compose.ui.text.style.TextAlign.Center,557    )558    Text(559        "active · yours forever",560        modifier = Modifier.fillMaxWidth().padding(top = 4.dp),561        color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,562        textAlign = androidx.compose.ui.text.style.TextAlign.Center,563    )564    Spacer(Modifier.height(12.dp))565    features.forEachIndexed { i, name ->566        RowLine(fg) {567            Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {568                Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))569                Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)570            }571            Text("unlocked", color = com.peachpasswords.ui.theme.PeachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)572        }573    }574    Spacer(Modifier.height(12.dp))575    Box(576        Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))577            .border(1.dp, com.peachpasswords.ui.theme.PeachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))578            .clickable { vm.deactivate() }579            .padding(vertical = 12.dp),580        contentAlignment = Alignment.Center,581    ) { Text("Deactivate", color = com.peachpasswords.ui.theme.PeachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }582}583584/* ──────────────────────────────  Feedback  ───────────────────────────────── */585586@OptIn(ExperimentalLayoutApi::class)587@Composable588private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {589    val categories = listOf("Bug report", "Feature request", "Question", "Other")590    var category by remember { mutableStateOf(categories[0]) }591    var message by remember { mutableStateOf("") }592    val state by vm.feedbackState.collectAsState()593594    // Reset transient state when the card leaves composition so reopening starts fresh.595    DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }596597    if (state is FeedbackState.Sent) {598        Box(599            Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))600                .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),601        ) {602            Column {603                Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)604                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))605            }606        }607        return608    }609610    val sending = state is FeedbackState.Sending611612    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)613    SubLabel("TYPE", fg)614    FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {615        categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }616    }617    SubLabel("MESSAGE", fg)618    Box(619        Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))620            .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))621            .padding(10.dp),622    ) {623        if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)624        BasicTextField(625            value = message, onValueChange = { message = it },626            enabled = !sending,627            textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),628            cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),629        )630    }631    Spacer(Modifier.height(8.dp))632633    Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {634        val canSend = !sending && message.isNotBlank()635        Box(636            Modifier.clip(RoundedCornerShape(8.dp))637                .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))638                .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))639                .clickable(enabled = canSend) { vm.sendFeedback(category, message) }640                .padding(horizontal = 12.dp, vertical = 6.dp),641        ) {642            Text(643                if (state is FeedbackState.Error) "Retry" else "Send",644                color = fg.copy(alpha = if (canSend) 1f else 0.4f),645                fontFamily = PeachType.Mono, fontSize = 11.sp,646            )647        }648        if (sending) {649            CircularProgressIndicator(650                color = LocalPeachAccent.current,651                strokeWidth = 2.dp,652                modifier = Modifier.size(16.dp),653            )654        }655    }656657    (state as? FeedbackState.Error)?.let { err ->658        Text(659            err.message,660            modifier = Modifier.padding(top = 8.dp),661            color = PeachColors.Breach,662            fontFamily = PeachType.Mono,663            fontSize = 11.sp,664            lineHeight = 15.sp,665        )666    }667668    Hint("Sent anonymously · no account required", fg)669}