1package com.peachpasswords.ui.vault23456789101112131415161718import androidx.compose.foundation.background19import androidx.compose.foundation.border20import androidx.compose.foundation.clickable21import androidx.compose.foundation.layout.Box22import androidx.compose.foundation.layout.Column23import androidx.compose.foundation.layout.Spacer24import androidx.compose.foundation.layout.fillMaxWidth25import androidx.compose.foundation.layout.height26import androidx.compose.foundation.layout.padding27import androidx.compose.foundation.layout.size28import androidx.compose.foundation.shape.CircleShape29import androidx.compose.foundation.shape.RoundedCornerShape30import androidx.compose.material.icons.Icons31import androidx.compose.material.icons.outlined.Build32import androidx.compose.material3.ExperimentalMaterial3Api33import androidx.compose.material3.Icon34import androidx.compose.material3.ModalBottomSheet35import androidx.compose.material3.Text36import androidx.compose.material3.rememberModalBottomSheetState37import androidx.compose.runtime.Composable38import androidx.compose.runtime.getValue39import androidx.compose.runtime.mutableStateOf40import androidx.compose.runtime.remember41import androidx.compose.runtime.setValue42import androidx.compose.ui.Alignment43import androidx.compose.ui.Modifier44import androidx.compose.ui.draw.clip45import androidx.compose.ui.text.font.FontStyle46import androidx.compose.ui.unit.dp47import androidx.compose.ui.unit.sp48import com.peachpasswords.ui.theme.LocalPeachAccent49import com.peachpasswords.ui.theme.PeachColors50import com.peachpasswords.ui.theme.PeachType51import com.peachpasswords.vault.PasswordGenerator525354@Composable55internal fun WrenchButton(onClick: () -> Unit) {56 Icon(57 Icons.Outlined.Build,58 contentDescription = "generate password",59 tint = PeachColors.T2,60 modifier = Modifier61 .size(36.dp)62 .clip(CircleShape)63 .clickable(onClick = onClick)64 .padding(9.dp), 65 )66}67686970717273@param74@param75@param76@param7778@OptIn(ExperimentalMaterial3Api::class)79@Composable80internal fun GeneratorSheet(81 copied: Boolean,82 onCopy: (String) -> Unit,83 onUse: (String) -> Unit,84 onDismiss: () -> Unit,85) {86 val accent = LocalPeachAccent.current87 val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)8889 var length by remember { mutableStateOf(20) }90 var upper by remember { mutableStateOf(true) }91 var lower by remember { mutableStateOf(true) }92 var numbers by remember { mutableStateOf(true) }93 var symbols by remember { mutableStateOf(true) }94 var draft by remember { mutableStateOf("") }9596 fun gen() {97 draft = PasswordGenerator.generate(98 PasswordGenerator.Options(99 length = length,100 includeUppercase = upper,101 includeLowercase = lower,102 includeNumbers = numbers,103 includeSymbols = symbols,104 ),105 )106 }107108 ModalBottomSheet(109 onDismissRequest = onDismiss,110 sheetState = sheetState,111 containerColor = PeachColors.S1,112 ) {113 Column(Modifier.fillMaxWidth().padding(horizontal = 20.dp, vertical = 4.dp)) {114 Text(115 "generate password",116 color = PeachColors.T0,117 fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp,118 )119 Spacer(Modifier.height(8.dp))120121 122 Box(123 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))124 .border(1.dp, PeachColors.T3, RoundedCornerShape(10.dp))125 .padding(horizontal = 12.dp, vertical = 14.dp),126 ) {127 Text(128 text = draft.ifEmpty { "tap generate" },129 color = if (draft.isEmpty()) PeachColors.T2 else PeachColors.T0,130 fontFamily = PeachType.Mono, fontSize = 13.sp,131 )132 }133 Spacer(Modifier.height(6.dp))134135 136 GeneratorBody(137 length = length,138 upper = upper, lower = lower, numbers = numbers, symbols = symbols,139 password = draft, copied = copied,140 onLength = { length = it },141 onUpper = { upper = it }, onLower = { lower = it },142 onNumbers = { numbers = it }, onSymbols = { symbols = it },143 onGenerate = { gen() },144 onCopy = { if (draft.isNotEmpty()) onCopy(draft) },145 )146147 148 Box(149 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))150 .background(if (draft.isEmpty()) accent.copy(alpha = 0.10f) else accent.copy(alpha = 0.18f))151 .border(1.dp, accent.copy(alpha = 0.5f), RoundedCornerShape(10.dp))152 .clickable(enabled = draft.isNotEmpty()) { onUse(draft) }153 .padding(vertical = 14.dp),154 contentAlignment = Alignment.Center,155 ) {156 Text(157 "use this password",158 color = if (draft.isEmpty()) accent.copy(alpha = 0.5f) else accent,159 fontFamily = PeachType.Mono, fontSize = 12.sp,160 )161 }162 Spacer(Modifier.height(20.dp))163 }164 }165}