package com.peachpasswords.ui.vault /* * D4 drafts — drop-in replacement for the private GeneratorDrawer in * EntryEditScreen.kt PLUS a shared generator body + a detail bottom-sheet wrapper. * * This file is a DRAFT staging area. The orchestrator should: * 1. Replace the existing private GeneratorDrawer in EntryEditScreen.kt with the * GeneratorDrawer below (signature gains `password`, `copied`, `onCopy`). * 2. Move GeneratorBody + the detail sheet into the real ui/vault package * (they already declare `package com.peachpasswords.ui.vault`). * * See INTEGRATION.md for exact anchors and the VM additions required. */ import androidx.compose.animation.core.animateDpAsState import androidx.compose.animation.core.tween import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Slider import androidx.compose.material3.SliderDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clipToBounds import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.peachpasswords.ui.components.CopyButton import com.peachpasswords.ui.theme.LocalPeachAccent import com.peachpasswords.ui.theme.PeachColors import com.peachpasswords.ui.theme.PeachMotion import com.peachpasswords.ui.theme.PeachType /** * Drop-in replacement for the private GeneratorDrawer in EntryEditScreen.kt. * * Adds a [Copy] drain button beside "generate" that copies the *current* password * to the clipboard using the shared spec §4.4 CopyButton. The drawer still fills * the password field on generate; copy is an explicit extra affordance. * * New params vs the original: `password`, `copied`, `onCopy`. The drawer height * grows to fit the extra action row. */ @Composable internal fun GeneratorDrawer( open: Boolean, length: Int, upper: Boolean, lower: Boolean, numbers: Boolean, symbols: Boolean, password: String, copied: Boolean, onLength: (Int) -> Unit, onUpper: (Boolean) -> Unit, onLower: (Boolean) -> Unit, onNumbers: (Boolean) -> Unit, onSymbols: (Boolean) -> Unit, onGenerate: () -> Unit, onCopy: () -> Unit, ) { val height by animateDpAsState( targetValue = if (open) 234.dp else 0.dp, animationSpec = tween(320, easing = PeachMotion.Spring), label = "gen-drawer", ) Box( Modifier.fillMaxWidth().height(height).clipToBounds() .clip(RoundedCornerShape(12.dp)).background(PeachColors.S2), ) { GeneratorBody( length = length, upper = upper, lower = lower, numbers = numbers, symbols = symbols, password = password, copied = copied, onLength = onLength, onUpper = onUpper, onLower = onLower, onNumbers = onNumbers, onSymbols = onSymbols, onGenerate = onGenerate, onCopy = onCopy, ) } if (open) Spacer(Modifier.height(14.dp)) } /** * Shared generator UI body — used both inside the inline drawer (EntryEditScreen) * and inside the detail ModalBottomSheet. Stateless: parent owns option state and * the generated password. The "generate" row carries the [Copy] drain button. */ @Composable internal fun GeneratorBody( length: Int, upper: Boolean, lower: Boolean, numbers: Boolean, symbols: Boolean, password: String, copied: Boolean, onLength: (Int) -> Unit, onUpper: (Boolean) -> Unit, onLower: (Boolean) -> Unit, onNumbers: (Boolean) -> Unit, onSymbols: (Boolean) -> Unit, onGenerate: () -> Unit, onCopy: () -> Unit, ) { val accent = LocalPeachAccent.current Column(Modifier.fillMaxWidth().padding(16.dp)) { Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) { Text("GENERATOR", color = PeachColors.T1, fontFamily = PeachType.Mono, fontSize = 8.sp) Text("length $length", color = accent, fontFamily = PeachType.Mono, fontSize = 9.sp) } Slider( value = length.toFloat(), onValueChange = { onLength(it.toInt()) }, valueRange = 8f..128f, colors = SliderDefaults.colors( thumbColor = accent, activeTrackColor = accent, inactiveTrackColor = PeachColors.T3, ), ) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { TogglePill("A-Z", upper, onUpper) TogglePill("a-z", lower, onLower) TogglePill("0-9", numbers, onNumbers) TogglePill("!@#", symbols, onSymbols) } Spacer(Modifier.height(12.dp)) Row(verticalAlignment = Alignment.CenterVertically) { Box( Modifier.weight(1f).clip(RoundedCornerShape(10.dp)) .border(1.dp, accent.copy(alpha = 0.5f), RoundedCornerShape(10.dp)) .background(accent.copy(alpha = 0.10f)) .clickable(onClick = onGenerate).padding(vertical = 12.dp), contentAlignment = Alignment.Center, ) { Text("generate", color = accent, fontFamily = PeachType.Mono, fontSize = 12.sp) } // [Copy] drain button — disabled-feel when no password yet (no-op click). Spacer(Modifier.width(8.dp)) CopyButton(copied = copied, onCopy = { if (password.isNotEmpty()) onCopy() }) } } } /** * Local copy of the option toggle pill. Identical to the private TogglePill in * EntryEditScreen — when the orchestrator merges GeneratorBody into the real file * it should DELETE this duplicate and reuse the existing private TogglePill. */ @Composable private fun TogglePill(label: String, on: Boolean, onToggle: (Boolean) -> Unit) { val accent = LocalPeachAccent.current Box( Modifier.clip(RoundedCornerShape(8.dp)) .border(1.dp, if (on) accent.copy(alpha = 0.5f) else PeachColors.T3, RoundedCornerShape(8.dp)) .background(if (on) accent.copy(alpha = 0.10f) else Color.Transparent) .clickable { onToggle(!on) } .padding(horizontal = 10.dp, vertical = 6.dp), ) { Text(label, color = if (on) accent else PeachColors.T2, fontFamily = PeachType.Mono, fontSize = 9.sp) } }