package com.peachpasswords.ui.settings import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.peachpasswords.vault.VaultRepository import com.peachpasswords.vault.VaultSettings import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class SettingsViewModel @Inject constructor( private val vault: VaultRepository, ) : ViewModel() { val entries: StateFlow> = vault.entries val settings: StateFlow = vault.settings /** Pro entitlement is not wired until Phase 8 sync/license — Pro-gated for now. */ val isPro: Boolean = false private fun mutate(block: (VaultSettings) -> VaultSettings) { viewModelScope.launch { vault.updateSettings(block(vault.settings.value)) } } fun setTheme(theme: String) = mutate { it.copy(theme = theme) } fun setAccent(name: String) = mutate { it.copy(accentColor = name) } fun setTextSize(size: String) = mutate { it.copy(textSize = size) } fun setReduceMotion(on: Boolean) = mutate { it.copy(reduceMotion = on) } fun setBreachMonitoring(on: Boolean) = mutate { it.copy(breachMonitoring = on) } fun setBiometrics(on: Boolean) = mutate { it.copy(biometricsEnabled = on) } fun setAutoLockMinutes(min: Int?) = mutate { it.copy(autoLockMinutes = min) } fun setTrashRetentionDays(days: Int?) = mutate { it.copy(trashRetentionDays = days) } suspend fun changePassword(current: String, next: String): Boolean = vault.changePassword(current, next) /** One-line summary shown under each card title; mirrors the browser ledes. */ fun lede(id: CardId, entriesCount: Int, s: VaultSettings): String = when (id) { CardId.Pro -> if (isPro) "active · paid once, yours forever" else "$39 once · yours forever" CardId.Protection -> "${if (s.breachMonitoring) "breaches watched" else "breach watch off"} · manual lock" CardId.Vault -> "$entriesCount ${if (entriesCount == 1) "entry" else "entries"} · backups, history, cleanup" CardId.Sync -> if (isPro) "pair by chirp, keep in step" else "Pro · encrypted device pairing" CardId.Appearance -> "${s.theme} · ${s.accentColor} · ${s.textSize}" CardId.Shortcuts -> "bindings · what your fingers know" CardId.Feedback -> "tell us what would make it better" } }